public class

CheckBox

extends ButtonBase
implements IsEditor<E extends Editor<?>> HasName HasValue<T> HasWordWrap
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.FocusWidget
         ↳ com.google.gwt.user.client.ui.ButtonBase
           ↳ com.google.gwt.user.client.ui.CheckBox
Known Direct Subclasses

Class Overview

A standard check box widget. This class also serves as a base class for RadioButton.

CSS Style Rules

.gwt-CheckBox
the outer element
.gwt-CheckBox-disabled
applied when Checkbox is disabled

Example

{@example com.google.gwt.examples.CheckBoxExample}

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
CheckBox()
Creates a check box with no label.
CheckBox(SafeHtml label)
Creates a check box with the specified text label.
CheckBox(String label)
Creates a check box with the specified text label.
CheckBox(String label, boolean asHTML)
Creates a check box with the specified text label.
Protected Constructors
CheckBox(Element elem)
Public Methods
HandlerRegistration addValueChangeHandler(ValueChangeHandler<Boolean> handler)
LeafValueEditor<Boolean> asEditor()
Returns the Editor encapsulated by the view object.
String getFormValue()
Returns the value property of the input element that backs this widget.
String getHTML()
Gets this object's contents as HTML.
String getName()
Gets the widget's name.
int getTabIndex()
Gets the tab index.
String getText()
Gets this object's text.
Boolean getValue()
Determines whether this check box is currently checked.
boolean getWordWrap()
Gets whether word-wrapping is enabled.
boolean isChecked()
This method is deprecated. Use getValue() instead
boolean isEnabled()
Gets whether this widget is enabled.
void setAccessKey(char key)
Sets the widget's 'access key'.
void setChecked(boolean checked)
This method is deprecated. Use setValue(Boolean) instead
void setEnabled(boolean enabled)
Sets whether this widget is enabled.
void setFocus(boolean focused)
Explicitly focus/unfocus this widget.
void setFormValue(String value)
Set the value property on the input element that backs this widget.
void setHTML(String html)
Sets this object's contents via HTML.
void setName(String name)
Sets the widget's name.
void setTabIndex(int index)
Sets the widget's position in the tab index.
void setText(String text)
Sets this object's text.
void setValue(Boolean value, boolean fireEvents)
Checks or unchecks the check box, firing ValueChangeEvent if appropriate.
void setValue(Boolean value)
Checks or unchecks the check box.
void setWordWrap(boolean wrap)
Sets whether word-wrapping is enabled.
void sinkEvents(int eventBitsToAdd)
Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement.
Protected Methods
void ensureDomEventHandlers()
void onEnsureDebugId(String baseID)
Affected Elements:
  • -label = label next to checkbox.
void onLoad()
This method is called when a widget is attached to the browser's document.
void onUnload()
This method is called when a widget is detached from the browser's document.
void replaceInputElement(Element elem)
Replace the current input element with a new one.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.ButtonBase
From class com.google.gwt.user.client.ui.FocusWidget
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.editor.client.IsEditor
From interface com.google.gwt.event.dom.client.HasBlurHandlers
From interface com.google.gwt.event.dom.client.HasClickHandlers
From interface com.google.gwt.event.dom.client.HasDoubleClickHandlers
From interface com.google.gwt.event.dom.client.HasFocusHandlers
From interface com.google.gwt.event.dom.client.HasGestureChangeHandlers
From interface com.google.gwt.event.dom.client.HasGestureEndHandlers
From interface com.google.gwt.event.dom.client.HasGestureStartHandlers
From interface com.google.gwt.event.dom.client.HasKeyDownHandlers
From interface com.google.gwt.event.dom.client.HasKeyPressHandlers
From interface com.google.gwt.event.dom.client.HasKeyUpHandlers
From interface com.google.gwt.event.dom.client.HasMouseDownHandlers
From interface com.google.gwt.event.dom.client.HasMouseMoveHandlers
From interface com.google.gwt.event.dom.client.HasMouseOutHandlers
From interface com.google.gwt.event.dom.client.HasMouseOverHandlers
From interface com.google.gwt.event.dom.client.HasMouseUpHandlers
From interface com.google.gwt.event.dom.client.HasMouseWheelHandlers
From interface com.google.gwt.event.dom.client.HasTouchCancelHandlers
From interface com.google.gwt.event.dom.client.HasTouchEndHandlers
From interface com.google.gwt.event.dom.client.HasTouchMoveHandlers
From interface com.google.gwt.event.dom.client.HasTouchStartHandlers
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.logical.shared.HasValueChangeHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.safehtml.client.HasSafeHtml
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.TakesValue
From interface com.google.gwt.user.client.ui.Focusable
From interface com.google.gwt.user.client.ui.HasEnabled
From interface com.google.gwt.user.client.ui.HasHTML
From interface com.google.gwt.user.client.ui.HasName
From interface com.google.gwt.user.client.ui.HasText
From interface com.google.gwt.user.client.ui.HasValue
From interface com.google.gwt.user.client.ui.HasWordWrap
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.SourcesClickEvents
From interface com.google.gwt.user.client.ui.SourcesFocusEvents
From interface com.google.gwt.user.client.ui.SourcesKeyboardEvents
From interface com.google.gwt.user.client.ui.SourcesMouseEvents

Public Constructors

public CheckBox ()

Creates a check box with no label.

public CheckBox (SafeHtml label)

Creates a check box with the specified text label.

Parameters
label the check box's label

public CheckBox (String label)

Creates a check box with the specified text label.

Parameters
label the check box's label

public CheckBox (String label, boolean asHTML)

Creates a check box with the specified text label.

Parameters
label the check box's label
asHTML true to treat the specified label as html

Protected Constructors

protected CheckBox (Element elem)

Public Methods

public HandlerRegistration addValueChangeHandler (ValueChangeHandler<Boolean> handler)

public LeafValueEditor<Boolean> asEditor ()

Returns the Editor encapsulated by the view object.

Returns

public String getFormValue ()

Returns the value property of the input element that backs this widget. This is the value that will be associated with the CheckBox name and submitted to the server if a FormPanel that holds it is submitted and the box is checked.

Don't confuse this with getValue(), which returns true or false if the widget is checked.

public String getHTML ()

Gets this object's contents as HTML.

Returns
  • the object's HTML

public String getName ()

Gets the widget's name.

Returns
  • the widget's name

public int getTabIndex ()

Gets the tab index.

Returns
  • the tab index

public String getText ()

Gets this object's text.

Returns
  • the object's text

public Boolean getValue ()

Determines whether this check box is currently checked.

Note that this does not return the value property of the checkbox input element wrapped by this widget. For access to that property, see getFormValue()

Returns
  • true if the check box is checked, false otherwise. Will not return null

public boolean getWordWrap ()

Gets whether word-wrapping is enabled.

Returns
  • true if word-wrapping is enabled.

public boolean isChecked ()

This method is deprecated.
Use getValue() instead

Determines whether this check box is currently checked.

Returns
  • true if the check box is checked

public boolean isEnabled ()

Gets whether this widget is enabled.

Returns
  • true if the widget is enabled

public void setAccessKey (char key)

Sets the widget's 'access key'. This key is used (in conjunction with a browser-specific modifier key) to automatically focus the widget.

Parameters
key the widget's access key

public void setChecked (boolean checked)

This method is deprecated.
Use setValue(Boolean) instead

Checks or unchecks this check box. Does not fire ValueChangeEvent. (If you want the event to fire, use setValue(Boolean, boolean))

Parameters
checked true to check the check box.

public void setEnabled (boolean enabled)

Sets whether this widget is enabled.

Parameters
enabled true to enable the widget, false to disable it

public void setFocus (boolean focused)

Explicitly focus/unfocus this widget. Only one widget can have focus at a time, and the widget that does will receive all keyboard events.

Parameters
focused whether this widget should take focus or release it

public void setFormValue (String value)

Set the value property on the input element that backs this widget. This is the value that will be associated with the CheckBox's name and submitted to the server if a FormPanel that holds it is submitted and the box is checked.

Don't confuse this with setValue(T), which actually checks and unchecks the box.

public void setHTML (String html)

Sets this object's contents via HTML. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using setText(String) whenever possible.

Parameters
html the object's new HTML

public void setName (String name)

Sets the widget's name.

Parameters
name the widget's new name

public void setTabIndex (int index)

Sets the widget's position in the tab index. If more than one widget has the same tab index, each such widget will receive focus in an arbitrary order. Setting the tab index to -1 will cause this widget to be removed from the tab order.

Parameters
index the widget's tab index

public void setText (String text)

Sets this object's text.

Parameters
text the object's new text

public void setValue (Boolean value, boolean fireEvents)

Checks or unchecks the check box, firing ValueChangeEvent if appropriate.

Note that this does not set the value property of the checkbox input element wrapped by this widget. For access to that property, see setFormValue(String)

Parameters
value true to check, false to uncheck; null value implies false
fireEvents If true, and value has changed, fire a ValueChangeEvent

public void setValue (Boolean value)

Checks or unchecks the check box.

Note that this does not set the value property of the checkbox input element wrapped by this widget. For access to that property, see setFormValue(String)

Parameters
value true to check, false to uncheck; null value implies false

public void setWordWrap (boolean wrap)

Sets whether word-wrapping is enabled.

Parameters
wrap true to enable word-wrapping.

public void sinkEvents (int eventBitsToAdd)

Overridden to defer the call to super.sinkEvents until the first time this widget is attached to the dom, as a performance enhancement. Subclasses wishing to customize sinkEvents can preserve this deferred sink behavior by putting their implementation behind a check of isOrWasAttached():

 @Override
 public void sinkEvents(int eventBitsToAdd) {
   if (isOrWasAttached()) {
     /* customized sink code goes here */
   } else {
     super.sinkEvents(eventBitsToAdd);
  }
} 

Parameters
eventBitsToAdd a bitfield representing the set of events to be added to this element's event set

Protected Methods

protected void ensureDomEventHandlers ()

protected void onEnsureDebugId (String baseID)

Affected Elements:

  • -label = label next to checkbox.

Parameters
baseID the base ID used by the main element

protected void onLoad ()

This method is called when a widget is attached to the browser's document. onAttach needs special handling for the CheckBox case. Must still call onAttach() to preserve the onAttach contract.

protected void onUnload ()

This method is called when a widget is detached from the browser's document. Overridden because of IE bug that throws away checked state and in order to clear the event listener off of the inputElem.

protected void replaceInputElement (Element elem)

Replace the current input element with a new one. Preserves all state except for the name property, for nasty reasons related to radio button grouping. (See implementation of setName(String).)

Parameters
elem the new input element