Class ToggleButton

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

  • Constructor Details

    • 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, ClickHandler handler)
      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
      handler - the click handler
    • ToggleButton

      @Deprecated public ToggleButton(Image upImage, ClickListener listener)
      Deprecated.
      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, ClickHandler handler)
      Constructor for ToggleButton.
      Parameters:
      upImage - image for the default(up) face of the button
      downImage - image for the down face of the button
      handler - the click handler
    • ToggleButton

      @Deprecated 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, ClickHandler handler)
      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
      handler - the click handler
    • ToggleButton

      @Deprecated public ToggleButton(String upText, ClickListener listener)
      Deprecated.
      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
    • ToggleButton

      public ToggleButton(String upText, String downText, ClickHandler handler)
      Constructor for ToggleButton.
      Parameters:
      upText - the text for the default (up) face of the button
      downText - the text for down face of the button
      handler - the click handler
  • Method Details