Correct usage of component size hints
Posted on 2004-09-14
This question is about the correct way to use the setPreferredSize, setMaximumSize and setMinimumSize functions.
I'm teaching myself Java by designing an application. I'm particularly keen to get it looking aesthetically pleasing but I also don't want to break all the rules regarding Java's multi-platform support.
Bearing these two things in mind, could people tell me what I'm doing right/wrong in the following:
My application is a bit like an install program - several pages connected by "forward" and "back" buttons. Each page has a panel containing data at the top, and a thin panel containing the buttons at the bottom. There are two main things I want regarding size of components:
1) When the vertical window size is changed by the user I want the bottom panel containing the buttons to stay a constant height, and the top pannel to expand. To do this currently I use
lowerpanel.setMaximumSize(new Dimension(999999, 40);
I've set width to be 999999 because I don't care how wide it gets - I just want it to expand to fill the full width. However, this doesn't seem likely to be the best way to do it to me! (?)
2) I want the 'forward' and 'back' buttons to be the same size, and to take up a fair amount of the bottom panel, but leave a gap of blank space between them, which expands when the window is expanded horizontally.
To do this I use
Again this just doesn't seem right to me. Is there a better way?
And in general should I be using all these set max and min size methods? Is this bad java programming because it might screw up the way it looks on other platforms?