Class TriStateJCheckBox

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
EnablingTriStateCheckboxRenderer

public class TriStateJCheckBox extends JPanel
JPanel containing Extension of JCheckBox allowing a partial state to be displayed. The partial state is in the form of a small square, a style similar to Google Earth. If Checkbox is pressed when unchecked, state changes to checked. If Checkbox is pressed when checked, state changes to unchecked. If Checkbox is pressed when partial, state changes to unchecked. User can only check / un-check the checkbox, the partial state is only available programatically. State can be set by enum or an array of boolean values. The enum of the actual state can be obtained, isSelected() returns false when in a partial state.

Inspired by postings of 843806 https://community.oracle.com/tech/developers/discussion/1354306/is-there-a-tri-state-check-box-in-swing s1w_ https://stackoverflow.com/questions/1263323/tristate-checkboxes-in-java

See Also:
  • Constructor Details

    • TriStateJCheckBox

      Creates a check box. Defaults to unchecked state.
    • TriStateJCheckBox

      public TriStateJCheckBox(String labelText)
      Creates a check box with text. Defaults to unchecked state.
      Parameters:
      labelText - the text of the check box.
  • Method Details

    • setState

      Set the new state to either CHECKED, PARTIAL or UNCHECKED.
      Parameters:
      state - enum of new state.
    • setState

      public void setState(boolean[] booleanArray)
      Set the new state using values within a boolean array. boolean[]{false,false} = UNCHECKED boolean[]{true,true} = CHECKED boolean[]{true,false} = PARTIAL
      Parameters:
      booleanArray - boolean values to compare
    • getState

      Return the current state, which is determined by the selection status of the model.
      Returns:
      enum of current state.
    • setSelected

      public void setSelected(boolean selected)
      Set the CheckBox to Selected or Unselected.
      Parameters:
      selected - true for selected, else false.
    • isSelected

      public boolean isSelected()
      Is the CheckBox currently fully selected?
      Returns:
      true if CHECKED, false for UNCHECKED and PARTIAL.
    • setEnabled

      public void setEnabled(boolean enabled)
      Set the CheckBox enabled or disabled.
      Overrides:
      setEnabled in class JComponent
      Parameters:
      enabled - true for enabled, false disabled.
    • setText

      public void setText(String newText)
      Set the CheckBox Label Text if different from constructor.
      Parameters:
      newText - New Text Label.
    • addActionListener

      Add an ActionListener to the JCheckBox.
      Parameters:
      al - the ActionListener to add.
    • setToolTipText

      public void setToolTipText(String s)
      Overrides:
      setToolTipText in class JComponent