Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making the text field width match.

 
Darrin Smith
Ranch Hand
Posts: 276
  • Mark post as helpful
  • send pies
  • 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!
 
Eric Snell
Greenhorn
Posts: 28
Java Mac MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic