• 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
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Making the text field width match.

 
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a column of text fields, then at the bottom, on another panel I have a total. It looks like this:

Label1 Label2
Col1 Col2 Col3 Col4
Col1 Col2 Col3 Col4
Col1 Col2 Col3 Col4
Col1 Col2 Col3 Col4
Col1 Col2 Col3 Col4
Total ____ Total ____ <--Fields in question on another panel.

What I want is to have the "Total" JLabel line up directly under the Col1 and Col3 JTextFields and have the ____ JTextField line up directly under the Col2 and Col4 JTextFields.

The Col JTextFields are on their own panel, and the Total and ____ fields are on a seperate panel (did this so the Label and Col fields would line up at the top correctly).

The way I have things now is using a BoxLayout, putting everything in the first area (col1 and col2) on one panel along with the Label1, and everything in the second area (col3 and col4) on another panel along with the Label2. Both of these then go on another panel (BoxLayout XAxis).

This panel then goes on another (BoxLayout...YAxis) along with the panel that holds the Total and ____ fields.

How can I get everything to line up? I've tried tweaking with struts, but that seems like a real hack.

Thanks!
 
Greenhorn
Posts: 28
Mac MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could set the preferred sizes of the fields to be the same so that they will naturally layout directly underneath one another.

Or you could use GridBagLayout.
 
Why am I so drawn to cherry pie? I can't seem to stop. Save me tiny ad!
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic