Google Web Toolkit
Search Google Code:

# Class ToggleButton

public class ToggleButton
extends CustomButton
A `ToggleButton` is a stylish stateful button which allows the user to toggle between `up` and `down` states.

### CSS Style Rules

- .gwt-ToggleButton-up/down/up-hovering/down-hovering/up-disabled/down-disabled {.html-face}

### Example

    public class ToggleButtonExample implements EntryPoint {
      public void onModuleLoad() {
        // Make a new button that does something when you click it.
        final ToggleButton toggleButton = new ToggleButton("Up", "Down");
        toggleButton.addClickListener(new ClickListener() {
          public void onClick(Widget sender) {
            if (toggleButton.isDown()) {
              Window.alert("I have been toggled down");
            } else {
              Window.alert("I have been toggled up");
            }
          }
        });

        // In a real application, you would have to have css styles defined for
        // gwt-ToggleButton-up,gwt-ToggleButton-up-hovering,gwt-ToggleButton-up-disabled,
        // gwt-ToggleButton-down,.gwt-ToggleButton-down-hovering,.gwt-ToggleButton-down-disabled

        // Add the ToggleButton to the root panel.
        RootPanel.get().add(toggleButton);
      }
    }

## Constructors

ToggleButton() | Constructor for `ToggleButton`.
ToggleButton(Image) | Constructor for `ToggleButton`.
ToggleButton(Image, ClickListener) | Constructor for `ToggleButton`.
ToggleButton(Image, Image) | Constructor for `ToggleButton`.
ToggleButton(Image, Image, ClickListener) | Constructor for `ToggleButton`.
ToggleButton(String) | Constructor for `ToggleButton`.
ToggleButton(String, ClickListener) | Constructor for `ToggleButton`.
ToggleButton(String, String) | Constructor for `ToggleButton`.

## Methods

isDown() | Is this button down?
onClick() | Called when the user finishes clicking on this button.
setDown(boolean) | Sets whether this button is down.

## Constructor Detail

### ToggleButton

public ToggleButton()
Constructor for `ToggleButton`.

### ToggleButton

public ToggleButton(Image upImage)
Constructor for `ToggleButton`. The supplied image is used to construct the default face.

#### Parameters

upImage
  image for the default face of the button

### ToggleButton

public ToggleButton(Image upImage, ClickListener listener)
Constructor for `ToggleButton`. The supplied image is used to construct the default face of the button.

#### Parameters

upImage
  image for the default (up) face of the button
listener
  the click listener

### ToggleButton

public ToggleButton(Image upImage, Image downImage)
Constructor for `ToggleButton`.

#### Parameters

upImage
  image for the default(up) face of the button
downImage
  image for the down face of the button

### ToggleButton

public ToggleButton(Image upImage, Image downImage, ClickListener listener)
Constructor for `ToggleButton`.

#### Parameters

upImage
  image for the default(up) face of the button
downImage
  image for the down face of the button
listener
  clickListener

### ToggleButton

public ToggleButton(String upText)
Constructor for `ToggleButton`. The supplied text is used to construct the default face of the button.

#### Parameters

upText
  the text for the default (up) face of the button.

### ToggleButton

public ToggleButton(String upText, ClickListener listener)
Constructor for `ToggleButton`. The supplied text is used to construct the default face of the button.

#### Parameters

upText
  the text for the default (up) face of the button
listener
  the click listener

### ToggleButton

public ToggleButton(String upText, String downText)
Constructor for `ToggleButton`.

#### Parameters

upText
  the text for the default (up) face of the button
downText
  the text for down face of the button

## Method Detail

### isDown

protected boolean isDown()
Is this button down?

#### Return Value

`true` if the button is down

### onClick

protected void onClick()
Called when the user finishes clicking on this button. The default behavior is to fire the click event to listeners. Subclasses that override onClickStart() should override this method to restore the normal widget display.

### setDown

protected void setDown(boolean down)
Sets whether this button is down.

#### Parameters

down
  `true` to press the button, `false` otherwise