public class

ToggleButton

extends CustomButton
implements IsEditor<E extends Editor<?>> HasValue<T>
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.FocusWidget
         ↳ com.google.gwt.user.client.ui.ButtonBase
           ↳ com.google.gwt.user.client.ui.CustomButton
             ↳ com.google.gwt.user.client.ui.ToggleButton

Class Overview

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

{@example com.google.gwt.examples.ToggleButtonExample}

Summary

[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
ToggleButton()
Constructor for ToggleButton.
ToggleButton(Image upImage)
Constructor for ToggleButton.
ToggleButton(Image upImage, ClickHandler handler)
Constructor for ToggleButton.
ToggleButton(Image upImage, ClickListener listener)
This constructor is deprecated. Use ToggleButton(Image, ClickHandler) instead
ToggleButton(Image upImage, Image downImage)
Constructor for ToggleButton.
ToggleButton(Image upImage, Image downImage, ClickHandler handler)
Constructor for ToggleButton.
ToggleButton(Image upImage, Image downImage, ClickListener listener)
This constructor is deprecated. Use ToggleButton(Image, Image, ClickHandler) instead
ToggleButton(String upText)
Constructor for ToggleButton.
ToggleButton(String upText, ClickHandler handler)
Constructor for ToggleButton.
ToggleButton(String upText, ClickListener listener)
This constructor is deprecated. Use ToggleButton(String, ClickHandler) instead
ToggleButton(String upText, String downText)
Constructor for ToggleButton.
ToggleButton(String upText, String downText, ClickHandler handler)
Constructor for ToggleButton.
Public Methods
HandlerRegistration addValueChangeHandler(ValueChangeHandler<Boolean> handler)
LeafValueEditor<Boolean> asEditor()
Returns the Editor encapsulated by the view object.
Boolean getValue()
Determines whether this button is currently down.
boolean isDown()
Is this button down?
void setDown(boolean down)
Sets whether this button is down. Does not fire ValueChangeEvent.
void setValue(Boolean value, boolean fireEvents)
Sets whether this button is down, firing ValueChangeEvent if appropriate.
void setValue(Boolean value)
Sets whether this button is down.
Protected Methods
void onClick()
Called when the user finishes clicking on this button.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.CustomButton
From class com.google.gwt.user.client.ui.ButtonBase
From class com.google.gwt.user.client.ui.FocusWidget
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.editor.client.IsEditor
From interface com.google.gwt.event.dom.client.HasBlurHandlers
From interface com.google.gwt.event.dom.client.HasClickHandlers
From interface com.google.gwt.event.dom.client.HasDoubleClickHandlers
From interface com.google.gwt.event.dom.client.HasFocusHandlers
From interface com.google.gwt.event.dom.client.HasGestureChangeHandlers
From interface com.google.gwt.event.dom.client.HasGestureEndHandlers
From interface com.google.gwt.event.dom.client.HasGestureStartHandlers
From interface com.google.gwt.event.dom.client.HasKeyDownHandlers
From interface com.google.gwt.event.dom.client.HasKeyPressHandlers
From interface com.google.gwt.event.dom.client.HasKeyUpHandlers
From interface com.google.gwt.event.dom.client.HasMouseDownHandlers
From interface com.google.gwt.event.dom.client.HasMouseMoveHandlers
From interface com.google.gwt.event.dom.client.HasMouseOutHandlers
From interface com.google.gwt.event.dom.client.HasMouseOverHandlers
From interface com.google.gwt.event.dom.client.HasMouseUpHandlers
From interface com.google.gwt.event.dom.client.HasMouseWheelHandlers
From interface com.google.gwt.event.dom.client.HasTouchCancelHandlers
From interface com.google.gwt.event.dom.client.HasTouchEndHandlers
From interface com.google.gwt.event.dom.client.HasTouchMoveHandlers
From interface com.google.gwt.event.dom.client.HasTouchStartHandlers
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.logical.shared.HasValueChangeHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.safehtml.client.HasSafeHtml
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.TakesValue
From interface com.google.gwt.user.client.ui.Focusable
From interface com.google.gwt.user.client.ui.HasEnabled
From interface com.google.gwt.user.client.ui.HasHTML
From interface com.google.gwt.user.client.ui.HasText
From interface com.google.gwt.user.client.ui.HasValue
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.SourcesClickEvents
From interface com.google.gwt.user.client.ui.SourcesFocusEvents
From interface com.google.gwt.user.client.ui.SourcesKeyboardEvents
From interface com.google.gwt.user.client.ui.SourcesMouseEvents

Public Constructors

public ToggleButton ()

Constructor for 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

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

public ToggleButton (Image upImage, ClickListener listener)

This constructor is deprecated.
Use ToggleButton(Image, ClickHandler) instead

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

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

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

public ToggleButton (Image upImage, Image downImage, ClickListener listener)

This constructor is deprecated.
Use ToggleButton(Image, Image, ClickHandler) instead

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

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.

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

public ToggleButton (String upText, ClickListener listener)

This constructor is deprecated.
Use ToggleButton(String, ClickHandler) instead

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

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

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

Public Methods

public HandlerRegistration addValueChangeHandler (ValueChangeHandler<Boolean> handler)

public LeafValueEditor<Boolean> asEditor ()

Returns the Editor encapsulated by the view object.

Returns

public Boolean getValue ()

Determines whether this button is currently down.

Returns
  • true if the button is pressed, false otherwise. Will not return null

public boolean isDown ()

Is this button down?

Returns
  • true if the button is down

public void setDown (boolean down)

Sets whether this button is down. Does not fire ValueChangeEvent. (If you want the event to fire, use setValue(Boolean, boolean))

Parameters
down true to press the button, false otherwise

public void setValue (Boolean value, boolean fireEvents)

Sets whether this button is down, firing ValueChangeEvent if appropriate.

Parameters
value true to press the button, false otherwise; null value implies false
fireEvents If true, and value has changed, fire a ValueChangeEvent

public void setValue (Boolean value)

Sets whether this button is down.

Parameters
value true to press the button, false otherwise; null value implies false

Protected Methods

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.