• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

about Layout Manager

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When I assigned the task of building a panel containing a TextArea at the top, a label directly below it, and a button directly below the label.
If the three components are added directly to the panel, which layout manager that selected can the panel use to ensure that the TextArea absorbs all of the free vertical space when the panel is resized?
There are two layout manager can be used,i.e GridLayout and GridBagLayout.But I don't make decision .which should I select?And why?
Thank u
 
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
GridLayout makes all its cells equal in size. Thus is not good for the job.
GridbagLayout, on the contrary, provides constraints objects to give a subcomponent all the extra space; and to customize its appearance in many ways.
Notice that BorderLayout would have been suitable if the middle component were to change its size, not the top one.
[ February 20, 2003: Message edited by: Jose Botella ]
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would do that with a BorderLayout - make a Panel with a GridLayout or FlowLayout to hold the label and the button - put the panel in the south position. Put the TextArea in the center position. You can also do this with GridBagLayout but it is more complex.
Bill
 
Jose Botella
Ranch Hand
Posts: 2120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If only a GridLayout is used for holding the label and the button, both will see its wide to vary because a south component varies horizontally.
If only a Flowlayout is used the label and the button will appear in a row.
Thus we need a panel with a GridLayout to hold the label and the button in a column. And also a panel with a FlowLayout to hold the previous panel to avoid the modification of the size its components.
 
reply
    Bookmark Topic Watch Topic
  • New Topic