Re: [問題] 如果不寫setLayout(null)會是什麼

作者: Expsun (無限燃燒)   2014-07-27 13:32:31
※ 引述《dharma (達)》之銘言:
: 沒寫setLayout(null)
: 程式碼裡面也沒寫BorderLayout、FlowLayout...那些
: 可是GUI還是可以run出來
: 這代表Java有預設什麼GUI配置嘛?
: 翻了幾本書
: 都沒提到
: 謝謝
http://docs.oracle.com/javase/tutorial/uiswing/layout/using.html
Setting the Layout Manager
...(略)
Each JPanel object is initialized to use a FlowLayout, unless you specify
differently when creating the JPanel. Content panes use BorderLayout by
default
...(略)
Although we strongly recommend that you use layout managers, you can perform
layout without them. By setting a container's layout property to null, you
make the container use no layout manager. With this strategy, called absolute
positioning, you must specify the size and position of every component within
that container. One drawback of absolute positioning is that it does not
adjust well when the top-level container is resized.
...
依tutorial內容所示
JPanel預設為FlowLayout
ContentPane預設為BorderLayout
而如果setLayout(boolean)傳入null
代表是絕對位置
容器放大、縮小就不會自動調整位置。
以上。
作者: dharma (達)   2014-07-27 13:38:00
要來熟悉官方英文文件

Links booklink

Contact Us: admin [ a t ] ucptt.com