Class FormPanel

All Implemented Interfaces:
ImageObserver, LayoutManager, MenuContainer, Serializable, Accessible

public class FormPanel extends JPanel implements LayoutManager
Panel that arranges components in a 2 x N grid. This layout is similar to how most web pages arrange their forms, and provides a good template layout for creating property panels and such. Some aspects of the form's appearance depend on the platform's user interface conventions.

Cells in the label column will get a certain percentage of the total available width, with all components in the value column sharing the remaining space. Components that are not marked as being a row (i.e. that were not added using one of the addRow(...) methods, will take up the entire row.

This class uses a custom LayoutManager to achieve the desired effect, changing the layout manager will mean these capabilities are lost.

See Also:
  • Constructor Details

    • FormPanel

      public FormPanel()
      Creates a FormPanel with alignments and margins conforming to the user interface conventions for the underlying platform.
  • Method Details

    • addRow

      @Deprecated public void addRow()
      Deprecated.
      Use the more clearly named addEmptyRow() instead.
      Adds an empty row.
    • addRow

      public void addRow(JComponent component)
      Adds a row that contains a single component that will use the entire available width.
    • addRow

      public void addRow(JComponent component, int height)
      Adds a row that contains a single component that will use the entire available width and the specified height.
    • addRow

      public void addRow(JComponent labelCell, JComponent valueCell)
      Adda a row that consists of the specified label and value cells.
    • addRow

      public void addRow(String label, JComponent valueCell)
      Adds a row that consists of the specified text label and value cells.
    • addRow

      public void addRow(String label, String valueLabel)
      Adds a row that consists of a text label and a value label.
    • addRow

      public void addRow(String label, JRadioButton... choices)
      Adds a row that consists of a text label in and a number of radio buttons.
    • addRow

      public void addRow(String label, JSlider slider, boolean addValueLabel)
      Adds a row that consists of a text label and a slider.
      Parameters:
      addValueLabel - When true, show the (numerical) slider value in a label displayed behind the slider.
    • addRow

      public void addRow(String label, String actionButtonText, Callable<String> action)
      Adds a row that consists of a text label and a button. Clicking the button will perform an action that results in the text label being updated.
      Parameters:
      action - Callback action invoked when the button is clicked. This should return the new text to be used for the text label.
    • addRow

      public void addRow(String label, String initialValueLabel, String actionButtonText, Callable<String> action)
      Adds a row that consists of a text label, a value label, and a button. Clicking the button will perform an action that results in the value label being updated.
      Parameters:
      action - Callback action invoked when the button is clicked. This should return the new text to be used for the value label.
    • addRow

      public void addRow(JButton button, boolean fullWidth)
      Adds a row that consists of a single button.
      Parameters:
      fullWidth - If true, the button will span the full width of the row. If false, it will only take its preferred width.
    • addRow

      public void addRow(String labelText)
      Adds a row that only consists of a single text label that spans the entire width of the row.
    • addRow

      public void addRow(String label, JComponent first, JComponent second)
      Adds a row that consists of a text label in the left column, and two components in the right column. The latter will be displayed using their native/preferred width to share the available space within the column.
    • addEllipsesRow

      public void addEllipsesRow(Supplier<String> labelProvider, Runnable callback)
      Adds a row with a text label and an ellipsis button (...) that when invoked will trigger a callback action, which will in turn update the label.
    • addBoldRow

      public void addBoldRow(String labelText)
      Adds a row that only consists of a single text label with a bold font that spans the entire width of the row.
    • addEmptyRow

      public void addEmptyRow()
      Adds an empty row that takes vertical space, but does not have any components in it.
    • addSpacerRow

      public void addSpacerRow(int height)
      Adds an empty row that takes the specified amount of vertical space.
    • packFormHeight

      public void packFormHeight()
      Updates the form's preferred height based on the minimum height that fits all rows. The form's height is automatically updated every time a row is added using one of the addRow(...) methods, but can also be called manually if one of the row components has changed and the form's layout needs to be updated.
    • setHorizontalMargin

      public void setHorizontalMargin(int horizontalMargin)
    • setVerticalMargin

      public void setVerticalMargin(int verticalMargin)
    • getVerticalMargin

      public int getVerticalMargin()
    • setRightAlignLabels

      public void setRightAlignLabels(boolean rightAlignLabels)
    • addLayoutComponent

      public void addLayoutComponent(String name, Component component)
      Specified by:
      addLayoutComponent in interface LayoutManager
    • removeLayoutComponent

      public void removeLayoutComponent(Component component)
      Specified by:
      removeLayoutComponent in interface LayoutManager
    • preferredLayoutSize

      public Dimension preferredLayoutSize(Container parent)
      Specified by:
      preferredLayoutSize in interface LayoutManager
    • minimumLayoutSize

      public Dimension minimumLayoutSize(Container parent)
      Specified by:
      minimumLayoutSize in interface LayoutManager
    • layoutContainer

      public void layoutContainer(Container parent)
      Specified by:
      layoutContainer in interface LayoutManager