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

java.lang.Object
  extended bycom.google.gwt.user.client.ui.UIObject
      extended bycom.google.gwt.user.client.ui.Widget
          extended bycom.google.gwt.user.client.ui.FocusWidget
              extended bycom.google.gwt.user.client.ui.ButtonBase
                  extended bycom.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

*

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);
  }
}


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.
 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.
 void setChecked(boolean checked)
          Checks or unchecks this check box.
 void setEnabled(boolean enabled)
          Sets whether this widget is enabled.
 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 setText(java.lang.String text)
          Sets this object's text.
 
Methods inherited from class com.google.gwt.user.client.ui.FocusWidget
addClickListener, addFocusListener, addKeyboardListener, getTabIndex, onBrowserEvent, removeClickListener, removeFocusListener, removeKeyboardListener, setAccessKey, setFocus, setTabIndex
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
getParent, isAttached, onAttach, onDetach, onLoad, removeFromParent
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleName, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleName, getTitle, isVisible, isVisible, removeStyleName, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setTitle, setVisible, setVisible, setWidth, sinkEvents, 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

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

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

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

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

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(java.lang.String) whenever possible.

Specified by:
setHTML in interface HasHTML
Overrides:
setHTML in class ButtonBase

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

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