• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

gui component sizes

 
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
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • 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.
 
Rancher
Posts: 43016
76
  • 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.
 
Author
Posts: 974
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic