开发者

Adding a component to a BorderLayout container without specifying position

I'm a novice Java programmer, and I'm trying to work out the behaviour of BorderLayout in a particular situation.

Say you have:

JFrame frame = new JFrame();
frame.add(new JLabel("Test"));

The defualt layout manager for JFrame is BorderLayout. According to the Java tutorial for BorderLayout, a position must always be specified, e.g. by:

frame.add(new JLabel("Test"),BorderLayout.CENTER);

So I'm confused by the fact that it is possible to add a component without specifying a position. If I modify the above code to be:

JFrame frame = new JFrame();
frame.add(new JLabel("Test"));
frame.add(new JLabel("Test 2"));
frame.add(new JLabel("Test 3",BorderLayout.NORTH);

I get Test 2 being displayed in the center left of th开发者_如何学Ce screen, and Test 3 being displayed in the top left of the screen.

Am I right in my understanding that, if no position is specified, BorderLayout will just default to BorderLayout.CENTER and, if so, can anyone show me where this is documented? I'm sure it must be documented somewhere, but I can't find it anywhere!

Thanks


http://download.oracle.com/javase/6/docs/api/java/awt/BorderLayout.html

"As a convenience, BorderLayout interprets the absence of a string specification the same as the constant CENTER"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜