Class CheckBoxArray

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class CheckBoxArray extends JPanel
Multi-column panel of check boxes and optional radio-button groups.
See Also:
  • Field Details

  • Constructor Details

    • CheckBoxArray

      public CheckBoxArray(int numColumns, int hgap, int vgap)
      Create an empty check box array with the given column layout.
      Parameters:
      numColumns - number of columns; must be positive
      hgap - horizontal gap in pixels between columns
      vgap - vertical gap in pixels between check boxes within a column; negative values are clamped to zero
      Throws:
      IllegalArgumentException - if numColumns is not positive
    • CheckBoxArray

      public CheckBoxArray(int numColumns, int hgap, int vgap, String... labels)
      Create a check box array pre-populated with one unchecked, enabled, ungrouped check box per label, in black text with no item listener.
      Parameters:
      numColumns - number of columns; must be positive
      hgap - horizontal gap in pixels between columns
      vgap - vertical gap in pixels between check boxes within a column; negative values are clamped to zero
      labels - labels of the check boxes to add, one per box
      Throws:
      IllegalArgumentException - if numColumns is not positive
  • Method Details

    • add

      public CheckBoxData add(String label, boolean initialState, boolean enabled, ItemListener itemListener, Color textColor)
      Add an ungrouped check box, placed in the next column in round-robin order (see add(String, boolean, boolean, String, ItemListener, Color)).
      Parameters:
      label - the check box's label and lookup key
      initialState - initial checked state
      enabled - initial enabled state
      itemListener - listener notified of check/uncheck events, or null for none
      textColor - label text color
      Returns:
      the new check box's data holder
    • add

      public CheckBoxData add(String label, boolean initialState, boolean enabled, long bits, long mask, ItemListener itemListener, Color textColor)
      Conditionally add an ungrouped check box, gated by a bitmask test.

      The check box is added only when (bits & mask) == mask (i.e. every bit in mask is set in bits|); otherwise nothing is added and this method returns null without error.

      Parameters:
      label - the check box's label and lookup key
      initialState - initial checked state
      enabled - initial enabled state
      bits - the feature-flag bits to test
      mask - the bits that must all be set in bits for the check box to be added
      itemListener - listener notified of check/uncheck events, or null for none
      textColor - label text color
      Returns:
      the new check box's data holder, or null if (bits & mask) != mask
    • add

      public CheckBoxData add(String label, boolean initialState, boolean enabled, String buttonGroupName, ItemListener itemListener, Color textColor)
      Add a check box, optionally as part of a mutually-exclusive (radio-button-like) group.

      Check boxes are placed into columns in round-robin order: each call places its box in the next column after the previous call's, wrapping back to the first column after the last.

      Parameters:
      label - the check box's label and lookup key (used by getButton(java.lang.String), isSelected(java.lang.String), etc.)
      initialState - initial checked state
      enabled - initial enabled state
      buttonGroupName - name of the mutually-exclusive group to join, or null for an ungrouped (independent) check box
      itemListener - listener notified of check/uncheck events, or null for none
      textColor - label text color
      Returns:
      the new check box's data holder
    • getActiveButton

      public AbstractButton getActiveButton(String buttonGroupName)
      Parameters:
      buttonGroupName - name of a group previously used with add(String, boolean, boolean, String, ItemListener, Color)
      Returns:
      the currently-selected button in that group, or null if the group doesn't exist or has no selection
    • setSelected

      public void setSelected(String label, boolean selected)
      Set a check box's checked state; a no-op if no box has this label.
      Parameters:
      label - the check box's label
      selected - the new checked state
    • isSelected

      public boolean isSelected(String label)
      Parameters:
      label - the check box's label
      Returns:
      true if a box with this label exists and is checked
    • isEnabled

      public boolean isEnabled(String label)
      Parameters:
      label - the check box's label
      Returns:
      true if a box with this label exists and is enabled
    • setEnabled

      public void setEnabled(String label, boolean enabled)
      Set a check box's enabled state; a no-op if no box has this label.
      Parameters:
      label - the check box's label
      enabled - the new enabled state
    • getButton

      public AbstractButton getButton(String label)
      Parameters:
      label - the check box's label
      Returns:
      the button with this label, or null if none exists