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.setIndeterminate(false);

    MnemonicParsing is enabled by default for CheckBox.

    Since:
    JavaFX 2.0
    • Constructor Detail

      • 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 Detail

      • setIndeterminate

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

        public final boolean isIndeterminate​()
        Gets the value of the property indeterminate.
        Property description:
        Determines whether the CheckBox is in the indeterminate state.
      • setSelected

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

        public final boolean isSelected​()
        Gets the value of the property selected.
        Property description:
        Indicates whether this CheckBox is checked.
      • setAllowIndeterminate

        public final void setAllowIndeterminate​(boolean value)
        Sets the value of the property allowIndeterminate.
        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.
      • isAllowIndeterminate

        public final boolean isAllowIndeterminate​()
        Gets the value of the property allowIndeterminate.
        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.
      • 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.
        See Also:
        isAllowIndeterminate(), setAllowIndeterminate(boolean)
      • 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
      • createDefaultSkin

        protected Skin<?> createDefaultSkin​()
        Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).
        Overrides:
        createDefaultSkin in class Control
        Returns:
        new instance of default skin for this control. If null then the control will have no skin unless one is provided by css.
      • queryAccessibleAttribute

        public Object queryAccessibleAttribute​(AccessibleAttribute attribute,
                                               Object... parameters)
        This method is called by the assistive technology to request the value for an attribute.

        This method is commonly overridden by subclasses to implement attributes that are required for a specific role.
        If a particular attribute is not handled, the superclass implementation must be called.

        Overrides:
        queryAccessibleAttribute in class Control
        Parameters:
        attribute - the requested attribute
        parameters - optional list of parameters
        Returns:
        the value for the requested attribute
        See Also:
        AccessibleAttribute