fillRightPct parameter

The fillRightPct feature chooses when to right justify components based on their stretchability. Stretchability is the difference between a component's preferred and minimum widths. So if a component has the same preferred and minimum width, it has no stretchaility, and will only right justify when forced to by a fillRightPct of 1. In this layout, the default fillRightPct is 30%, per line 2 of the source code below. If a component can reach the right side of its column by without exceeding 30% of its stretchability beyond its preferred size, then it will do so. The "City/State/Zip" field set has been specifically set to a fillRightPct of 1, per the last line of the source code, so it will always right justify.

The "Delivery Method" combo box determines the right boundary in column 1. The "Street" field determines the right boundary in column 2, and "City/State/Zip" are stretching to align with it. The other components cannot reach their respective right boundaries, so they are at their preferred widths.

"Invoice Item ID" can reach the right boundary of column 1. Notice that "Invoice Item ID" is wider here than in the above example. "Product" cannot reach, because combo boxes have 0 stretchability.

"Last Name" can stretch to reach.

Both "Last Name" and "First Name/MI" can stretch to reach.

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 Remaining"), new JTextField(3), 3, 1, FormPanel.FREE_FIELD);

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);
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);