Class ToggleButton

java.lang.Object
All Implemented Interfaces:
IsEditor<LeafValueEditor<Boolean>>, HasAllDragAndDropHandlers, HasAllFocusHandlers, HasAllGestureHandlers, HasAllKeyHandlers, HasAllMouseHandlers, HasAllTouchHandlers, HasBlurHandlers, HasClickHandlers, HasDoubleClickHandlers, HasDragEndHandlers, HasDragEnterHandlers, HasDragHandlers, HasDragLeaveHandlers, HasDragOverHandlers, HasDragStartHandlers, HasDropHandlers, HasFocusHandlers, HasGestureChangeHandlers, HasGestureEndHandlers, HasGestureStartHandlers, HasKeyDownHandlers, HasKeyPressHandlers, HasKeyUpHandlers, HasMouseDownHandlers, HasMouseMoveHandlers, HasMouseOutHandlers, HasMouseOverHandlers, HasMouseUpHandlers, HasMouseWheelHandlers, HasTouchCancelHandlers, HasTouchEndHandlers, HasTouchMoveHandlers, HasTouchStartHandlers, HasAttachHandlers, HasValueChangeHandlers<Boolean>, HasHandlers, HasSafeHtml, EventListener, TakesValue<Boolean>, Focusable, HasEnabled, HasFocus, HasHTML, HasText, HasValue<Boolean>, HasVisibility, IsWidget, SourcesClickEvents, SourcesFocusEvents, SourcesKeyboardEvents, SourcesMouseEvents

public class ToggleButton extends CustomButton implements HasValue<Boolean>, IsEditor<LeafValueEditor<Boolean>>
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.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        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);
  }
}