• 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
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Layout clarification

 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I am need to develop a UI where I need to capture data. So it will be a combination of Labels and TextFields on each line. For instance,


First Name -----------------
Last Name -----------------
Street -----------------


which layout can be used to best represent this.

regards

Vrinda
 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could use a GridLayout on your JFrame with 3 rows.
Each of these rows could contain a JPanel which uses a FlowLayout.
Each JPanel would contain one JLabel and one JTextField.

If you would like some example code, please let me know.
 
Vrinda Werdel
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Mark. Will try this approach.

regards
Vrinda
 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd use gridbag layout. It has a little bit of a learning curve, but if you want to be particular about how things line up it seems to be the best bet.
Unless you want to try a third party layout (like forms layout from jgoodies) which I've not used myself.

-Tad
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you want to guarantee they line up vertically then I recommend a GridBagLayout as Tad suggested. Here's a few hints to help you out with that. First, set the GridBagConstraints.fill to GridBagConstraints.NONE if you don't want your components to take up the entire cell. Second, use GridBagConstraints.anchor to set where they're positioned within the cell when the cell is bigger than the component. Third, use GridBagConstraints.weightx to specify the weighting to be given to it when assigning extra space.

So, in your example, to make vertical row of fields that look like this:



The setup would look something like this:



Obviously the variables ending in "Label" are the JLabel's and the variables ending in "Field" are the JTextField or whatever you're using.
 
To get a wish, you need a genie. To get a genie, you need a lamp. To get a lamp, you need a tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic