Class WCheckBox
public class WCheckBox extends WAbstractToggleButton
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);
w1.setChecked(false);
w2.setChecked(true);
w3.setChecked(true);
WCheckBox is an inline
widget.
CSS
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:
WAbstractToggleButton
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_
-
Constructor Summary
Constructors Constructor Description WCheckBox()
Creates a checkbox without label.WCheckBox(WContainerWidget parent)
Creates a checkbox without label.WCheckBox(java.lang.CharSequence text)
Creates a checkbox with given label.WCheckBox(java.lang.CharSequence text, WContainerWidget parent)
Creates a checkbox with given label. -
Method Summary
Modifier and Type Method Description CheckState
getCheckState()
Returns the check state.boolean
isPartialStateSelectable()
return partial state cyclingboolean
isTristate()
Returns whether the checkbox is tristate.void
setCheckState(CheckState state)
Sets the check state.void
setPartialStateSelectable(boolean t)
enable or disable cycling throught partial statevoid
setTristate()
Makes a tristate checkbox.void
setTristate(boolean tristate)
Makes a tristate checkbox.protected void
updateJSlot()
protected void
updateNextState()
Methods inherited from class eu.webtoolkit.jwt.WAbstractToggleButton
checked, getText, getTextFormat, getValueText, isChecked, isWordWrap, refresh, remove, setChecked, setChecked, setFormData, setText, setTextFormat, setUnChecked, setValueText, setWordWrap, unChecked
Methods inherited from class eu.webtoolkit.jwt.WFormWidget
changed, enableAjax, getEmptyText, getLabel, getPlaceholderText, getTabIndex, getValidator, isCanReceiveFocus, isReadOnly, propagateSetEnabled, render, selected, setEmptyText, setEnabled, setHidden, setPlaceholderText, setReadOnly, setToolTip, setValidator, validate, validated
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, blurred, callJavaScriptMember, childrenChanged, createDomElement, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getDomChanges, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, jsStringLiteral, jsStringLiteral, parentResized, parentResized, propagateSetVisible, removeScript, removeStyleClass, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setDisabled, setFloatSide, setFocus, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setOffsets, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setSelectable, setStyleClass, setTabIndex, setThemeStyleEnabled, setVerticalAlignment, updateSignalConnection, voidEventSignal
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, removeChild, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setObjectName, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getObjectName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WCheckBox
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. -
WCheckBox
Creates a checkbox with given label. -
WCheckBox
public WCheckBox(java.lang.CharSequence text)Creates a checkbox with given label.
-
-
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()
-
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
Sets the check state.Unless it is a tri-state checkbox, only
CheckState.Checked
andCheckState.Unchecked
are valid states. -
getCheckState
Returns the check state. -
updateJSlot
protected void updateJSlot() -
updateNextState
protected void updateNextState()
-