• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java layout manager sizing

 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have the following code:


When it is run (Java 1.5) the JFrame displays only a portion of the title bar, the rest of the frame is as small as possible. The JButton takes up the entire JFrame, no matter how large or small I expand the JFrame to. I don't understand why:
1) The JFrame does not get sized to be large enough to display the button.
2) The Layout Manager does not honor the maximum size I set for the button.
[ December 05, 2008: Message edited by: Red Smith ]
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Red Smith:
When it is run (Java 1.5) the JFrame displays only a portion of the title bar, the rest of the frame is as small as possible. The JButton takes up the entire JFrame, no matter how large or small I expand the JFrame to. I don't understand why:
1) The JFrame does not get sized to be large enough to display the button.
2) The Layout Manager does not honor the maximum size I set for the button.

1) you have to call pack() or setSize() first. Without either the frame will keep an initial size of 0 by 0.

2) the default layout manager, BorderLayout, has a tendency to do what you describe: make the center component as large as possible. It completely ignores the maximum size. As do most layout managers, unfortunately.

If you switch to something else, e.g. FlowLayout, at least it won't resize anymore.
 
Red Smith
Ranch Hand
Posts: 136
1
Netscape Opera Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Rob!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!