作者Expsun (无限燃烧)
看板java
标题Re: [问题] 如果不写setLayout(null)会是什麽
时间Sun Jul 27 13:32:31 2014
※ 引述《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
代表是绝对位置
容器放大、缩小就不会自动调整位置。
以上。
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 175.182.21.168
※ 文章网址: http://webptt.com/cn.aspx?n=bbs/java/M.1406439153.A.283.html
1F:推 dharma:要来熟悉官方英文文件 07/27 13:38