Class FormPanel

java.lang.Object
be.imgn.swing.ui.FormPanel

public final class FormPanel extends Object
Lays out a form in two columns, with GridBagLayout, in the order its methods are called: rows of a label and its field, wide components across both columns, and section titles. Every cell has an inset of 4 pixels on each side, and the panel an empty border of 4 pixels. The wide components share the extra height; without one, the rows stay at the top of the panel.

The labels are typically Exposed fields of the view, so their texts and mnemonics come from its resources, as for any component.

Every method is called on the EDT. build() may be called once: any call afterwards throws IllegalStateException.

  • Method Details

    • create

      public static FormPanel create()
      Returns a new, empty form panel.
      Returns:
      the form panel
    • row

      public FormPanel row(JLabel label, JComponent field)
      Adds a label and its field: the label at the line end of the first column, the field filling the width of the second. Calls label.setLabelFor(field), so the label's mnemonic focuses the field.
      Parameters:
      label - the label
      field - the field
      Returns:
      this form panel
      Throws:
      IllegalStateException - if the panel was built
    • wide

      public FormPanel wide(JComponent component)
      Adds a component across both columns, filling the row's width and sharing the extra height with the other wide components, as a nested panel or a text area needs.
      Parameters:
      component - the component
      Returns:
      this form panel
      Throws:
      IllegalStateException - if the panel was built
    • section

      public FormPanel section(JLabel title)
      Adds a title across both columns: the label, followed by a JSeparator that fills the rest of the row, 4 pixels after it, on the label's trailing side whatever the component orientation.
      Parameters:
      title - the title
      Returns:
      this form panel
      Throws:
      IllegalStateException - if the panel was built
    • build

      public JPanel build()
      Returns the panel. It may be called once: any call on this form panel afterwards throws IllegalStateException.
      Returns:
      the panel
      Throws:
      IllegalStateException - if the panel was built