Class WCheckBox

public class WCheckBox
extends WAbstractToggleButton
A user control that represents a check box.

By default, a checkbox can have two states: CheckState.Checked or CheckState.Unchecked, which can be inspected using WAbstractToggleButton.isChecked(), and set using WAbstractToggleButton.setChecked().

A checkbox may also provide a third state, CheckState.PartiallyChecked, which is useful to indicate that it is neither checked nor unchecked. JWt will use native browser support for this HTML5 extension when available (Safari and MS IE), and use an image-based workaround otherwise. You may enable support for the third state using setTristate(), and use setCheckState() and getCheckState() to read all three states. Once a tri-state checkbox is clicked, it cycles through the states CheckState.Checked and CheckState.Unchecked.

A label is added as a sibling of the checkbox to the same parent.

Usage example:

 WGroupBox box = new WGroupBox("In-flight options");

 WCheckBox w1 = new WCheckBox("Vegetarian diet", box);
 box.addWidget(new WBreak());
 WCheckBox w2 = new WCheckBox("WIFI access", box);
 box.addWidget(new WBreak());
 WCheckBox w3 = new WCheckBox("AC plug", box);



WCheckBox is an inline widget.


This widget is rendered using an HTML <input type="checkbox"> tag. When a label is specified, the input element is nested in a <label>.

This widget does not provide styling, and can be styled using inline or external CSS as appropriate.

See Also:
  • Constructor Details

    • WCheckBox

      public WCheckBox​(WContainerWidget parentContainer)
      Creates a checkbox without label.

      A checkbox created by this constructor will not contain a placeholder for a label, and therefore it is not possible to assign a label to it later through WAbstractToggleButton#setText().

    • WCheckBox

      public WCheckBox()
      Creates a checkbox without label.

      Calls this((WContainerWidget)null)

    • WCheckBox

      public WCheckBox​(java.lang.CharSequence text, WContainerWidget parentContainer)
      Creates a checkbox with given label.
    • WCheckBox

      public WCheckBox​(java.lang.CharSequence text)
      Creates a checkbox with given label.

      Calls this(text, (WContainerWidget)null)

  • Method Details

    • setTristate

      public void setTristate​(boolean tristate)
      Makes a tristate checkbox.

      Note: You should enable tristate functionality right after construction and this cannot be modified later.

    • setTristate

      public final void setTristate()
      Makes a tristate checkbox.

      Calls setTristate(true)

    • setPartialStateSelectable

      public void setPartialStateSelectable​(boolean t)
      enable or disable cycling throught partial state

      See Also:
    • isPartialStateSelectable

      public boolean isPartialStateSelectable()
      return partial state cycling

      See Also:
      setPartialStateSelectable(boolean t)
    • isTristate

      public boolean isTristate()
      Returns whether the checkbox is tristate.

      See Also:
      setTristate(boolean tristate)
    • setCheckState

      public void setCheckState​(CheckState state)
      Sets the check state.

      Unless it is a tri-state checkbox, only CheckState.Checked and CheckState.Unchecked are valid states.

    • getCheckState

      public CheckState getCheckState()
      Returns the check state.

      See Also:
      setCheckState(CheckState state), WAbstractToggleButton.isChecked()
    • updateJSlot

      protected void updateJSlot()
    • updateNextState

      protected void updateNextState()