APIdia Launch Partner
Top Description Inners Fields Constructors Methods
com.badlogic.gdx.scenes.scene2d.ui

public Class Button

extends Table
implements Disableable, Styleable<Button.ButtonStyle>
Class Inheritance
All Implemented Interfaces
com.badlogic.gdx.scenes.scene2d.ui.Styleable, com.badlogic.gdx.scenes.scene2d.utils.Disableable
Known Direct Subclasses
com.badlogic.gdx.scenes.scene2d.ui.ImageButton, com.badlogic.gdx.scenes.scene2d.ui.ImageTextButton, com.badlogic.gdx.scenes.scene2d.ui.TextButton
Imports
com.badlogic.gdx.Gdx, com.badlogic.gdx.graphics.g2d.Batch, com.badlogic.gdx.scenes.scene2d.Actor, .InputEvent, .Stage, .Touchable, com.badlogic.gdx.scenes.scene2d.utils.ChangeListener.ChangeEvent, .ClickListener, .Disableable, .Drawable, com.badlogic.gdx.utils.Array, .Null

A button is a Table with a checked state and additional style fields for pressed, unpressed, and checked. Each time a button is clicked, the checked state is toggled. Being a table, a button can contain any other actors.

The button's padding is set to the background drawable's padding when the background changes, overwriting any padding set manually. Padding can still be set on the button's table cells.

ChangeEvent is fired when the button is clicked. Cancelling the event will restore the checked button state to what is was previously.

The preferred size of the button is determined by the background and the button contents.

Author
Nathan Sweet

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
Button.ButtonStyle

The style for a button, see Button.

Field Summary

Modifier and TypeField and Description
pack-priv ButtonGroup<T extends Button>
private ClickListener
pack-priv boolean
pack-priv boolean
private boolean
private Button.ButtonStyle
Inherited from com.badlogic.gdx.scenes.scene2d.ui.Table:
alignbackgroundbackgroundBottombackgroundLeftbackgroundRightbackgroundTopcellPooldebugdebugActorColordebugCellColordebugRectsdebugTableColorpadBottompadLeftpadRightpadTopround

Constructor Summary

AccessConstructor and Description
public
Button(Skin skin)

public
Button(Skin skin, String styleName)

public
Button(Actor child, Skin skin, String styleName)

public
public
public
Button()

Creates a button without setting the style or size.

public
public
public
Button(Drawable up, Drawable down, Drawable checked)

public
Button(Actor child, Skin skin)

Method Summary

Modifier and TypeMethod and Description
public void
draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Table.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget group is laid out.

protected Drawable
getBackgroundDrawable()

Returns appropriate background drawable from the style based on the current button state.

public ButtonGroup<T extends Button>
getButtonGroup()

Returns: May be null.

public ClickListener
public float
public float
public float
public float
public boolean
public Button.ButtonStyle
getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the button's style.

private void
public boolean
public boolean
public boolean
public boolean
public void
setChecked(boolean isChecked)

pack-priv void
setChecked(boolean isChecked, boolean fireEvent)

public void
setDisabled(boolean isDisabled)

Implements com.badlogic.gdx.scenes.scene2d.utils.Disableable.setDisabled.

When true, the button will not toggle isChecked() when clicked and will not fire a ChangeEvent.

public void
setProgrammaticChangeEvents(boolean programmaticChangeEvents)

If false, setChecked(boolean) and toggle() will not fire ChangeEvent.

public void
setStyle(Button.ButtonStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

public void
toggle()

Toggles the checked state.

Inherited from com.badlogic.gdx.scenes.scene2d.ui.Table:
addaddaddaddaddaddaddalignbackgroundbackgroundbottomcenterclearChildrenclipclipcolumnDefaultsdebugdebugdebugActordebugAlldebugCelldebugTabledefaultsdrawBackgrounddrawDebugdrawDebugBoundsgetAligngetBackgroundgetCellgetCellsgetClipgetColumnMinWidthgetColumnPrefWidthgetColumnsgetColumnWidthgetPadBottomgetPadBottomValuegetPadLeftgetPadLeftValuegetPadRightgetPadRightValuegetPadTopgetPadTopValuegetPadXgetPadYgetRowgetRowHeightgetRowMinHeightgetRowPrefHeightgetRowsgetSkingetTableDebughitinvalidatelayoutleftpadpadpadpadpadBottompadBottompadLeftpadLeftpadRightpadRightpadToppadTopremoveActorremoveActorremoveActorAtresetrightrowsetBackgroundsetBackgroundsetClipsetDebugsetRoundsetSkinstacktop

Field Detail

buttonGroupback to summary
pack-priv ButtonGroup<T extends Button> buttonGroup
clickListenerback to summary
private ClickListener clickListener
isCheckedback to summary
pack-priv boolean isChecked
isDisabledback to summary
pack-priv boolean isDisabled
programmaticChangeEventsback to summary
private boolean programmaticChangeEvents
styleback to summary
private Button.ButtonStyle style

Constructor Detail

Buttonback to summary
public Button(Skin skin)
Buttonback to summary
public Button(Skin skin, String styleName)
Buttonback to summary
public Button(Actor child, Skin skin, String styleName)
Buttonback to summary
public Button(Actor child, Button.ButtonStyle style)
Buttonback to summary
public Button(Button.ButtonStyle style)
Buttonback to summary
public Button()

Creates a button without setting the style or size. At least a style must be set before using this button.

Buttonback to summary
public Button(Drawable up)
Buttonback to summary
public Button(Drawable up, Drawable down)
Buttonback to summary
public Button(Drawable up, Drawable down, Drawable checked)
Buttonback to summary
public Button(Actor child, Skin skin)

Method Detail

drawback to summary
public void draw(Batch batch, float parentAlpha)

Overrides com.badlogic.gdx.scenes.scene2d.ui.Table.draw.

Doc from com.badlogic.gdx.scenes.scene2d.ui.WidgetGroup.draw.

If this method is overridden, the super method or validate() should be called to ensure the widget group is laid out.

getBackgroundDrawableback to summary
protected Drawable getBackgroundDrawable()

Returns appropriate background drawable from the style based on the current button state.

Annotations
@Null
getButtonGroupback to summary
public ButtonGroup<T extends Button> getButtonGroup()
Returns:ButtonGroup<T extends Button>

May be null.

Annotations
@Null
getClickListenerback to summary
public ClickListener getClickListener()
getMinHeightback to summary
public float getMinHeight()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Table.getMinHeight.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getMinHeight.

getMinWidthback to summary
public float getMinWidth()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Table.getMinWidth.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getMinWidth.

getPrefHeightback to summary
public float getPrefHeight()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Table.getPrefHeight.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefHeight.

getPrefWidthback to summary
public float getPrefWidth()

Overrides com.badlogic.gdx.scenes.scene2d.ui.Table.getPrefWidth.

Implements com.badlogic.gdx.scenes.scene2d.utils.Layout.getPrefWidth.

getProgrammaticChangeEventsback to summary
public boolean getProgrammaticChangeEvents()
getStyleback to summary
public Button.ButtonStyle getStyle()

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.getStyle.

Returns the button's style. Modifying the returned style may not have an effect until setStyle(ButtonStyle) is called.

initializeback to summary
private void initialize()
isCheckedback to summary
public boolean isChecked()
isDisabledback to summary
public boolean isDisabled()

Implements com.badlogic.gdx.scenes.scene2d.utils.Disableable.isDisabled.

isOverback to summary
public boolean isOver()
isPressedback to summary
public boolean isPressed()
setCheckedback to summary
public void setChecked(boolean isChecked)
setCheckedback to summary
pack-priv void setChecked(boolean isChecked, boolean fireEvent)
setDisabledback to summary
public void setDisabled(boolean isDisabled)

Implements com.badlogic.gdx.scenes.scene2d.utils.Disableable.setDisabled.

When true, the button will not toggle isChecked() when clicked and will not fire a ChangeEvent.

setProgrammaticChangeEventsback to summary
public void setProgrammaticChangeEvents(boolean programmaticChangeEvents)

If false, setChecked(boolean) and toggle() will not fire ChangeEvent. The event will only be fired only when the user clicks the button

setStyleback to summary
public void setStyle(Button.ButtonStyle style)

Implements com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Doc from com.badlogic.gdx.scenes.scene2d.ui.Styleable.setStyle.

Set the current style of the actor

toggleback to summary
public void toggle()

Toggles the checked state. This method changes the checked state, which fires a ChangeEvent (if programmatic change events are enabled), so can be used to simulate a button click.

com.badlogic.gdx.scenes.scene2d.ui back to summary

public Class Button.ButtonStyle

extends Object
Class Inheritance
Known Direct Subclasses
com.badlogic.gdx.scenes.scene2d.ui.ImageButton.ImageButtonStyle, com.badlogic.gdx.scenes.scene2d.ui.TextButton.TextButtonStyle

The style for a button, see Button.
Author
mzechner

Field Summary

Modifier and TypeField and Description
public Drawable
public Drawable
public Drawable
public float
public float
public Drawable
public Drawable
public Drawable
public Drawable
public Drawable
public float
public float
public float
public float
public Drawable

Constructor Summary

AccessConstructor and Description
public
public
public

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

checkedback to summary
public Drawable checked
Annotations
@Null
checkedDownback to summary
public Drawable checkedDown
Annotations
@Null
checkedFocusedback to summary
public Drawable checkedFocused
Annotations
@Null
checkedOffsetXback to summary
public float checkedOffsetX
checkedOffsetYback to summary
public float checkedOffsetY
checkedOverback to summary
public Drawable checkedOver
Annotations
@Null
disabledback to summary
public Drawable disabled
Annotations
@Null
downback to summary
public Drawable down
Annotations
@Null
focusedback to summary
public Drawable focused
Annotations
@Null
overback to summary
public Drawable over
Annotations
@Null
pressedOffsetXback to summary
public float pressedOffsetX
pressedOffsetYback to summary
public float pressedOffsetY
unpressedOffsetXback to summary
public float unpressedOffsetX
unpressedOffsetYback to summary
public float unpressedOffsetY
upback to summary
public Drawable up
Annotations
@Null

Constructor Detail

ButtonStyleback to summary
public ButtonStyle()
ButtonStyleback to summary
public ButtonStyle(Drawable up, Drawable down, Drawable checked)
ButtonStyleback to summary
public ButtonStyle(Button.ButtonStyle style)