*
The moose likes Swing / AWT / SWT and the fly likes gui component sizes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "gui component sizes" Watch "gui component sizes" New topic
Author

gui component sizes

Mandy Bowman
Ranch Hand

Joined: Jan 24, 2007
Posts: 32
Hi all,

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.

Mandy
Nathan Pruett
Bartender

Joined: Oct 18, 2000
Posts: 4121

It depends on the LayoutManager(s) in use.


-Nate
Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Mandy Bowman
Ranch Hand

Joined: Jan 24, 2007
Posts: 32
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: 41621
    
  55
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.


Ping & DNS - my free Android networking tools app
Mandy Bowman
Ranch Hand

Joined: Jan 24, 2007
Posts: 32
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: 862
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.


bitguru blog
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: gui component sizes