aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Making the text field width match. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Making the text field width match." Watch "Making the text field width match." New topic
Author

Making the text field width match.

Darrin Smith
Ranch Hand

Joined: Aug 04, 2003
Posts: 276
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

Joined: Jun 09, 2004
Posts: 28

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Making the text field width match.