FormLayout.addMultiRow() and FormLayout.LABEL_ON_TOP

The "Notes" field spans two rows, per the addMultiRow() call at then end of the source code below. It is given a starting row of 3 and an ending row of 5. The "Street", "City/State/Zip", and "Quantity/DeliveryMethod" fields occupy the adjacent column in those rows. Lines 7 and 10 are highlighted because they differ from the basic example. The notes field also uses the LABEL_ON_TOP feature, per the last line of the source code. It's label is put in the row specified, and the field is put in the subsequent row. LABEL_ON_TOP can be used with add() or addMultiRow() methods. The horizontal spacing is messy in the second column because the combo boxes are taller than the fields. This can be solved by modifying the combo boxes or the fields, by placing an invisible combo box in row 3, or some such tactic.

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, 5, 2);

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);
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.addMultiRow(new JLabel("Notes"), new JScrollPane(new JTextArea(4, 18)), 3, 5, 1, FormPanel.LABEL_ON_TOP);