Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.google.gwt.user.client.ui
Class CheckBox

    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

All Implemented Interfaces:
  EventListener, HasFocus, HasHTML, HasName, HasText, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents

Direct Known Subclasses:
  RadioButton

    public class CheckBox

extends ButtonBase
implements HasName

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

### CSS Style Rules

- .gwt-CheckBox { }
- .gwt-CheckBox-disabled { Applied when Checkbox is disabled }

### Example

>     public class CheckBoxExample implements EntryPoint {

>       public void onModuleLoad() {
>         // Make a new check box, and select it by default.
>         CheckBox cb = new CheckBox("Foo");
>         cb.setChecked(true);

>         // Hook up a listener to find out when it's clicked.
>         cb.addClickListener(new ClickListener() {
>           public void onClick(Widget sender) {
>             boolean checked = ((CheckBox) sender).isChecked();
>             Window.alert("It is " + (checked ? "" : "not") + "checked");
>           }
>         });

>         // Add it to the root panel.
>         RootPanel.get().add(cb);
>       }
>     }

Nested Class Summary

Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
`UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled`

Field Summary

Fields inherited from class com.google.gwt.user.client.ui.UIObject
`DEBUG_ID_PREFIX`

Constructor Summary
`` | `CheckBox()` Creates a check box with no label.
`protected` | `CheckBox(Element elem)`
`` | `CheckBox(java.lang.String label)` Creates a check box with the specified text label.
`` | `CheckBox(java.lang.String label, boolean asHTML)` Creates a check box with the specified text label.

Method Summary
`java.lang.String` | `getHTML()` Gets this object's contents as HTML.
`java.lang.String` | `getName()` Gets the widget's name.
`int` | `getTabIndex()` Gets the widget's position in the tab index.
`java.lang.String` | `getText()` Gets this object's text.
`boolean` | `isChecked()` Determines whether this check box is currently checked.
`boolean` | `isEnabled()` Gets whether this widget is enabled.
`protected void` | `onEnsureDebugId(java.lang.String baseID)` Affected Elements: -label = label next to checkbox.
`protected void` | `onLoad()` This method is called when a widget is attached to the browser's document.
`protected void` | `onUnload()` This method is called when a widget is detached from the browser's document.
`protected void` | `replaceInputElement(Element elem)` Replace the current input element with a new one.
`void` | `setAccessKey(char key)` Sets the widget's 'access key'.
`void` | `setChecked(boolean checked)` Checks or unchecks this check box.
`void` | `setEnabled(boolean enabled)` Sets whether this widget is enabled.
`void` | `setFocus(boolean focused)` Explicitly focus/unfocus this widget.
`void` | `setHTML(java.lang.String html)` Sets this object's contents via HTML.
`void` | `setName(java.lang.String name)` Sets the widget's name.
`void` | `setTabIndex(int index)` Sets the widget's position in the tab index.
`void` | `setText(java.lang.String text)` Sets this object's text.
`void` | `sinkEvents(int eventBitsToAdd)` Adds a set of events to be sunk by this object.

Methods inherited from class com.google.gwt.user.client.ui.FocusWidget
`addClickListener, addFocusListener, addKeyboardListener, getFocusImpl, onBrowserEvent, removeClickListener, removeFocusListener, removeKeyboardListener, setElement`

Methods inherited from class com.google.gwt.user.client.ui.Widget
`doAttachChildren, doDetachChildren, getParent, isAttached, onAttach, onDetach, removeFromParent`

Methods inherited from class com.google.gwt.user.client.ui.UIObject
`addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, removeStyleDependentName, removeStyleName, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents`

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### CheckBox

    public CheckBox()

  Creates a check box with no label.

### CheckBox

    public CheckBox(java.lang.String label)

  Creates a check box with the specified text label.

  Parameters:
    `label` - the check box's label

### CheckBox

    public CheckBox(java.lang.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

### CheckBox

    protected CheckBox(Element elem)

Method Detail

### getHTML

    public java.lang.String getHTML()

  Description copied from interface: `HasHTML`
  Gets this object's contents as HTML.

  Specified by:
    `getHTML` in interface `HasHTML`
  Overrides:
    `getHTML` in class `ButtonBase`
  Returns:
    the object's HTML

### getName

    public java.lang.String getName()

  Description copied from interface: `HasName`
  Gets the widget's name.

  Specified by:
    `getName` in interface `HasName`
  Returns:
    the widget's name

### getTabIndex

    public int getTabIndex()

  Description copied from interface: `HasFocus`
  Gets the widget's position in the tab index.

  Specified by:
    `getTabIndex` in interface `HasFocus`
  Overrides:
    `getTabIndex` in class `FocusWidget`
  Returns:
    the widget's tab index

### getText

    public java.lang.String getText()

  Description copied from interface: `HasText`
  Gets this object's text.

  Specified by:
    `getText` in interface `HasText`
  Overrides:
    `getText` in class `ButtonBase`
  Returns:
    the object's text

### isChecked

    public boolean isChecked()

  Determines whether this check box is currently checked.

  Returns:
    `true` if the check box is checked

### isEnabled

    public boolean isEnabled()

  Description copied from class: `FocusWidget`
  Gets whether this widget is enabled.

  Overrides:
    `isEnabled` in class `FocusWidget`
  Returns:
    `true` if the widget is enabled

### setAccessKey

    public void setAccessKey(char key)

  Description copied from interface: `HasFocus`
  Sets the widget's 'access key'. This key is used (in conjunction with a browser-specific modifier key) to automatically focus the widget.

  Specified by:
    `setAccessKey` in interface `HasFocus`
  Overrides:
    `setAccessKey` in class `FocusWidget`
  Parameters:
    `key` - the widget's access key

### setChecked

    public void setChecked(boolean checked)

  Checks or unchecks this check box.

  Parameters:
    `checked` - `true` to check the check box

### setEnabled

    public void setEnabled(boolean enabled)

  Description copied from class: `FocusWidget`
  Sets whether this widget is enabled.

  Overrides:
    `setEnabled` in class `FocusWidget`
  Parameters:
    `enabled` - `true` to enable the widget, `false` to disable it

### setFocus

    public void setFocus(boolean focused)

  Description copied from interface: `HasFocus`
  Explicitly focus/unfocus this widget. Only one widget can have focus at a time, and the widget that does will receive all keyboard events.

  Specified by:
    `setFocus` in interface `HasFocus`
  Overrides:
    `setFocus` in class `FocusWidget`
  Parameters:
    `focused` - whether this widget should take focus or release it

### setHTML

    public void setHTML(java.lang.String html)

  Description copied from interface: `HasHTML`
  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 `HasText.setText(String)` whenever possible.

  Specified by:
    `setHTML` in interface `HasHTML`
  Overrides:
    `setHTML` in class `ButtonBase`
  Parameters:
    `html` - the object's new HTML

### setName

    public void setName(java.lang.String name)

  Description copied from interface: `HasName`
  Sets the widget's name.

  Specified by:
    `setName` in interface `HasName`
  Parameters:
    `name` - the widget's new name

### setTabIndex

    public void setTabIndex(int index)

  Description copied from interface: `HasFocus`
  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.

  Specified by:
    `setTabIndex` in interface `HasFocus`
  Overrides:
    `setTabIndex` in class `FocusWidget`
  Parameters:
    `index` - the widget's tab index

### setText

    public void setText(java.lang.String text)

  Description copied from interface: `HasText`
  Sets this object's text.

  Specified by:
    `setText` in interface `HasText`
  Overrides:
    `setText` in class `ButtonBase`
  Parameters:
    `text` - the object's new text

### sinkEvents

    public void sinkEvents(int eventBitsToAdd)

  Description copied from class: `UIObject`
  Adds a set of events to be sunk by this object. Note that only `widgets` may actually receive events, but can receive events from all objects contained within them.

  Overrides:
    `sinkEvents` in class `UIObject`
  Parameters:
    `eventBitsToAdd` - a bitfield representing the set of events to be added to this element's event set
  See Also:
    `Event`

### onEnsureDebugId

    protected void onEnsureDebugId(java.lang.String baseID)

  Affected Elements:
  - -label = label next to checkbox.

  Overrides:
    `onEnsureDebugId` in class `UIObject`
  Parameters:
    `baseID` - the base ID used by the main element
  See Also:
    `UIObject.onEnsureDebugId(String)`

### onLoad

    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 `Widget.onAttach()` to preserve the `onAttach` contract.

  Overrides:
    `onLoad` in class `Widget`

### onUnload

    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`.

  Overrides:
    `onUnload` in class `Widget`

### replaceInputElement

    protected void replaceInputElement(Element elem)

  Replace the current input element with a new one.

  Parameters:
    `elem` - the new input element

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD