Class CheckBox

public class CheckBox
extends ButtonBase
implements HasName

// Superclass of RadioButton
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);
  }
}

Constructors

CheckBox()Creates a check box with no label.
CheckBox(String)Creates a check box with the specified text label.
CheckBox(String, boolean)Creates a check box with the specified text label.
CheckBox(Element)

Methods

getHTML()
getName()Gets the widget's name.
getTabIndex()
getText()
isChecked()Determines whether this check box is currently checked.
isEnabled()Gets whether this widget is enabled.
onLoad()This method is called when a widget is attached to the browser's document.
onUnload()This method is called when a widget is detached from the browser's document.
replaceInputElement(Element)Replace the current input element with a new one.
setAccessKey(char)
setChecked(boolean)Checks or unchecks this check box.
setEnabled(boolean)Sets whether this widget is enabled.
setFocus(boolean)
setHTML(String)
setName(String)Sets the widget's name.
setTabIndex(int)
setText(String)

Constructor Detail

CheckBox

public CheckBox()
Creates a check box with no label.

CheckBox

public CheckBox(String label)
Creates a check box with the specified text label.

Parameters

label
the check box's label

CheckBox

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

CheckBox

protected CheckBox(Element elem)

Parameters

elem

Method Detail

getHTML

public String getHTML()

getName

public String getName()
Gets the widget's name.

Return Value

the widget's name

getTabIndex

public int getTabIndex()

getText

public String getText()

isChecked

public boolean isChecked()
Determines whether this check box is currently checked.

Return Value

true if the check box is checked

isEnabled

public boolean isEnabled()
Gets whether this widget is enabled.

Return Value

true if the widget is enabled

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.

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.

replaceInputElement

protected void replaceInputElement(Element elem)
Replace the current input element with a new one.

Parameters

elem
the new input element

setAccessKey

public void setAccessKey(char key)

Parameters

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)
Sets whether this widget is enabled.

Parameters

enabled
true to enable the widget, false to disable it

setFocus

public void setFocus(boolean focused)

Parameters

focused

setHTML

public void setHTML(String html)

Parameters

html

setName

public void setName(String name)
Sets the widget's name.

Parameters

name
the widget's new name

setTabIndex

public void setTabIndex(int index)

Parameters

index

setText

public void setText(String text)

Parameters

text