Class CheckBox

All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class CheckBox extends ButtonBase
A tri-state selection Control typically skinned as a box with a checkmark or tick mark when checked. A CheckBox control can be in one of three states:
  • checked: indeterminate == false, checked == true
  • unchecked: indeterminate == false, checked == false
  • undefined: indeterminate == true
If a CheckBox is checked, then it is also by definition defined. When checked the CheckBox is typically rendered with a "check" or "tick" mark. A CheckBox is in this state if selected is true and indeterminate is false.

A CheckBox is unchecked if selected is false and indeterminate is false.

A CheckBox is undefined if indeterminate is true, regardless of the state of selected. A typical rendering would be with a minus or dash, to indicate an undefined or indeterminate state of the CheckBox. This is convenient for constructing tri-state checkbox based trees, for example, where undefined check boxes typically mean "inherit settings from the parent".

The allowIndeterminate variable, if true, allows the user to cycle through the undefined state. If false, the CheckBox is not in the indeterminate state, and the user is allowed to change only the checked state.

Example:

 CheckBox cb = new CheckBox("a checkbox");
 cb.setSelected(true);
Image of the CheckBox control

MnemonicParsing is enabled by default for CheckBox.

Since:
JavaFX 2.0
  • Property Details

  • Constructor Details

    • CheckBox

      public CheckBox()
      Creates a check box with an empty string for its label.
    • CheckBox

      public CheckBox(String text)
      Creates a check box with the specified text as its label.
      Parameters:
      text - A text string for its label.
  • Method Details

    • setIndeterminate

      public final void setIndeterminate(boolean value)
      Sets the value of the indeterminate property.
      Property description:
      Determines whether the CheckBox is in the indeterminate state.
      Parameters:
      value - the value for the indeterminate property
      See Also:
    • isIndeterminate

      public final boolean isIndeterminate()
      Gets the value of the indeterminate property.
      Property description:
      Determines whether the CheckBox is in the indeterminate state.
      Returns:
      the value of the indeterminate property
      See Also:
    • indeterminateProperty

      public final BooleanProperty indeterminateProperty()
      Determines whether the CheckBox is in the indeterminate state.
      Returns:
      the indeterminate property
      See Also:
    • setSelected

      public final void setSelected(boolean value)
      Sets the value of the selected property.
      Property description:
      Indicates whether this CheckBox is checked.
      Parameters:
      value - the value for the selected property
      See Also:
    • isSelected

      public final boolean isSelected()
      Gets the value of the selected property.
      Property description:
      Indicates whether this CheckBox is checked.
      Returns:
      the value of the selected property
      See Also:
    • selectedProperty

      public final BooleanProperty selectedProperty()
      Indicates whether this CheckBox is checked.
      Returns:
      the selected property
      See Also:
    • setAllowIndeterminate

      public final void setAllowIndeterminate(boolean value)
      Sets the value of the allowIndeterminate property.
      Property description:
      Determines whether the user toggling the CheckBox should cycle through all three states: checked, unchecked, and undefined. If true then all three states will be cycled through; if false then only checked and unchecked will be cycled.
      Parameters:
      value - the value for the allowIndeterminate property
      See Also:
    • isAllowIndeterminate

      public final boolean isAllowIndeterminate()
      Gets the value of the allowIndeterminate property.
      Property description:
      Determines whether the user toggling the CheckBox should cycle through all three states: checked, unchecked, and undefined. If true then all three states will be cycled through; if false then only checked and unchecked will be cycled.
      Returns:
      the value of the allowIndeterminate property
      See Also:
    • allowIndeterminateProperty

      public final BooleanProperty allowIndeterminateProperty()
      Determines whether the user toggling the CheckBox should cycle through all three states: checked, unchecked, and undefined. If true then all three states will be cycled through; if false then only checked and unchecked will be cycled.
      Returns:
      the allowIndeterminate property
      See Also:
    • fire

      public void fire()
      Toggles the state of the CheckBox. If allowIndeterminate is true, then each invocation of this function will advance the CheckBox through the states checked, unchecked, and undefined. If allowIndeterminate is false, then the CheckBox will only cycle through the checked and unchecked states, and forcing indeterminate to equal to false.
      Specified by:
      fire in class ButtonBase