In building a GUI there are various methods for setting the sizes of components. For instance setSize, setPreferredSize, setMaximumSize, setMinimumSize and what I was wondering is which components is one meant to set the sizes for and which methods does one use and when. For instance if I have a frame that contains a panel (that is as big as the frame) which contains 2 panels which each contain buttons, textboxes and such which of these components do we set sizes on and what methods do we use. How do we decide? Currently, what I do is do whatever seems to work after lengthy trial and error.
-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Mandy Bowman
Ranch Hand
Joined: Jan 24, 2007
Posts: 32
posted
0
ok assume that the outer frame uses borderlayout and the panel that it contains also uses borderlayout but the two panels that it contains both uses flowlayout to arrange the textboxes, buttons etc in them.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35224
7
posted
0
What are you trying to achieve by calling any of the set[XYZ]Size methods? I generally call Frame.pack() after all components are added; that way everything gets sized to preferred size.
i am using setPrefferedSize and pack but as i understand it setPrefferedsize is not always adhered to by swing.
Brian Cole
Author
Ranch Hand
Joined: Sep 20, 2005
Posts: 852
posted
0
Originally posted by Mandy Bowman: i am using setPrefferedSize and pack but as i understand it setPrefferedsize is not always adhered to by swing.
Well there are defined situations in which the preferred size is ignored, such as in GridLayout or the CENTER of BorderLayout. But even then the preferred size of the component is used to determine the preferred size reported by the container.