This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Rust Web Development and have Bastian Gruber on-line!
See this thread for details.
Win a copy of Rust Web Development this week in the Other Languages forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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.
 
If you settle for what they are giving you, you deserve what you get. Fight for this tiny ad!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic