FormLayout.FREE_LABEL

As in the FREE_FIELD example, the "Country" field is allowed to align by itself, so the labels in the second column don't get too far from their fields. The difference here is that the "Country" field is much larger, so that now it pushes the width of the panel in an unsightly way.

The mode FormLayout.FREE_LABEL has been applied to the "Country" field. The flow of the form is upset a little bit in exchange for overall integrity.

Panel Construction Code

m_formPanel = new FormPanel(8, 5, 8, 8);
m_formPanel.setDefaultFillRightPct(.3);
// FormPanel extends JPanel,
// has FormLayout as the default layout manager,
// and exposes all the methods of FormLayout


m_formPanel.add(new JLabel("Invoice Item ID"), new JTextField(8), 1, 1);

JComboBox productCB = new JComboBox();
productCB.addItem("Lawn Mower");
m_formPanel.add(new JLabel("Product"), productCB, 2, 1);

m_formPanel.add(new JLabel("Quantity"), new JTextField(3), 5, 2);

JComboBox deliveryCB = new JComboBox();
deliveryCB.addItem("10 Day Ground");
m_formPanel.add(new JLabel("Delivery Method"), deliveryCB, 4, 1);

m_formPanel.add(new JLabel("First Name"), new JTextField(14), 1, 2);
m_formPanel.add(new JLabel("MI"), new JTextField(2), 1, 2);
m_formPanel.add(new JLabel("Last Name"), new JTextField(21), 2, 2);

m_formPanel.add(new JLabel("Street"), new JTextField(30), 3, 2, 0.0); // default fillRightPct of .3 no longer works

m_formPanel.add(new JLabel("City"), new JTextField(15), 4, 2);
m_formPanel.add(new JLabel("State"), new JTextField(2), 4, 2);
m_formPanel.add(new JLabel("Zip"), new JTextField(5), 4, 2, 1);

//m_formPanel.add(new JLabel("Country (if outside the U.S.)"), new JTextField(30), 5, 2, FormLayout.FREE_FIELD); // stretches the form sloppily
m_formPanel.add(new JLabel("Country (if outside the U.S.)"), new JTextField(30), 5, 2, FormLayout.FREE_LABEL);