• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

gui component sizes

 
Mandy Bowman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It depends on the LayoutManager(s) in use.
 
Mandy Bowman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mandy Bowman
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am using setPrefferedSize and pack but as i understand it setPrefferedsize is not always adhered to by swing.
 
Brian Cole
Author
Ranch Hand
Posts: 907
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic