Class CampaignOptionsPairedFieldGridPanel

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
mekhq.gui.campaignOptions.components.CampaignOptionsPairedFieldGridPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class CampaignOptionsPairedFieldGridPanel extends JPanel
A dense, column-aligned grid of label/control pairs for sections that hold many short fields.

Each label/control pair is laid out in its own fixed-width sub-panel, and the sub-panels are arranged into columnCount columns using a GridBagLayout. Because every pair sub-panel is given the same width (per column position), the control columns line up vertically regardless of individual label lengths — the key difference from packing pairs with a plain row grid. Pairs are filled row-major (left to right, then top to bottom), and a trailing filler absorbs any extra horizontal space so the grid stays left-aligned within a wider section.

The first column can be given a different width from the following columns (via firstPairWidth versus followingPairWidth); each control is pinned to controlWidth so the controls are uniform.

See Also:
  • Constructor Details

    • CampaignOptionsPairedFieldGridPanel

      public CampaignOptionsPairedFieldGridPanel(@Nonnull String name, int firstPairWidth, int followingPairWidth, int controlWidth, int columnCount)
      Creates a paired-field grid.
      Parameters:
      name - the panel's base name; the Swing component name becomes "pnl" + name
      firstPairWidth - the total width of each pair sub-panel in the first column (label + gap + control)
      followingPairWidth - the total width of each pair sub-panel in every column after the first
      controlWidth - the fixed width applied to every control so controls line up
      columnCount - the number of pair columns; must be at least 1
      Throws:
      IllegalArgumentException - if columnCount is less than 1
  • Method Details

    • addPairs

      public void addPairs(@Nonnull JComponent[] labels, @Nonnull JComponent[] controls)
      Adds every label/control pair to the grid in row-major order and appends the trailing filler. The two arrays are matched by index, so labels[i] is paired with controls[i].
      Parameters:
      labels - the label components, one per pair
      controls - the control components, one per pair, matching labels by index
      Throws:
      IllegalArgumentException - if the two arrays have different lengths