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