posted 19 years ago
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.