public class Button extends Table implements Disableable
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.
ChangeListener.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.
| Modifier and Type | Class and Description |
|---|---|
static class |
Button.ButtonStyle
The style for a button, see
Button. |
Table.Debug, Table.DebugRectbackgroundBottom, backgroundLeft, backgroundRight, backgroundTop, debugActorColor, debugCellColor, debugTableColor| Constructor and Description |
|---|
Button()
Creates a button without setting the style or size.
|
Button(Actor child,
Button.ButtonStyle style) |
Button(Actor child,
Skin skin) |
Button(Actor child,
Skin skin,
java.lang.String styleName) |
Button(Button.ButtonStyle style) |
Button(Drawable up) |
Button(Drawable up,
Drawable down) |
Button(Drawable up,
Drawable down,
Drawable checked) |
Button(Skin skin) |
Button(Skin skin,
java.lang.String styleName) |
| Modifier and Type | Method and Description |
|---|---|
void |
draw(Batch batch,
float parentAlpha)
If this method is overridden, the super method or
WidgetGroup.validate() should be called to ensure the widget group is laid
out. |
ButtonGroup |
getButtonGroup() |
ClickListener |
getClickListener() |
float |
getMinHeight() |
float |
getMinWidth() |
float |
getPrefHeight() |
float |
getPrefWidth() |
Button.ButtonStyle |
getStyle()
Returns the button's style.
|
boolean |
isChecked() |
boolean |
isDisabled() |
boolean |
isOver() |
boolean |
isPressed() |
void |
setChecked(boolean isChecked) |
void |
setDisabled(boolean isDisabled)
When true, the button will not toggle
isChecked() when clicked and will not fire a ChangeListener.ChangeEvent. |
void |
setProgrammaticChangeEvents(boolean programmaticChangeEvents)
If false,
setChecked(boolean) and toggle() will not fire ChangeListener.ChangeEvent, event will be fired only
when user clicked the button |
void |
setStyle(Button.ButtonStyle style) |
void |
toggle()
Toggles the checked state.
|
add, add, add, add, add, add, add, align, background, background, bottom, center, clearChildren, columnDefaults, debug, debug, debugActor, debugAll, debugCell, debugTable, defaults, drawBackground, drawDebug, drawDebugBounds, getAlign, getBackground, getCell, getCells, getClip, getColumnMinWidth, getColumnPrefWidth, getColumns, getColumnWidth, getPadBottom, getPadBottomValue, getPadLeft, getPadLeftValue, getPadRight, getPadRightValue, getPadTop, getPadTopValue, getPadX, getPadY, getRow, getRowHeight, getRowMinHeight, getRowPrefHeight, getRows, getSkin, getTableDebug, hit, invalidate, layout, left, pad, pad, pad, pad, padBottom, padBottom, padLeft, padLeft, padRight, padRight, padTop, padTop, removeActor, removeActor, reset, right, row, setBackground, setBackground, setClip, setDebug, setRound, setSkin, stack, topchildrenChanged, getMaxHeight, getMaxWidth, invalidateHierarchy, needsLayout, pack, setFillParent, setLayoutEnabled, sizeChanged, validateact, addActor, addActorAfter, addActorAt, addActorBefore, applyTransform, applyTransform, clear, computeTransform, drawChildren, drawDebugChildren, findActor, getChildren, getCullingArea, hasChildren, isTransform, localToDescendantCoordinates, resetTransform, resetTransform, setCullingArea, setDebug, setStage, setTransform, swapActor, swapActor, toStringaddAction, addCaptureListener, addListener, clearActions, clearListeners, clipBegin, clipBegin, clipEnd, fire, firstAscendant, getActions, getCaptureListeners, getColor, getDebug, getHeight, getListeners, getName, getOriginX, getOriginY, getParent, getRight, getRotation, getScaleX, getScaleY, getStage, getTop, getTouchable, getUserObject, getWidth, getX, getX, getY, getY, getZIndex, hasActions, hasParent, isAscendantOf, isDescendantOf, isTouchable, isVisible, localToAscendantCoordinates, localToParentCoordinates, localToStageCoordinates, moveBy, notify, parentToLocalCoordinates, positionChanged, remove, removeAction, removeCaptureListener, removeListener, rotateBy, rotationChanged, scaleBy, scaleBy, screenToLocalCoordinates, setBounds, setColor, setColor, setHeight, setName, setOrigin, setOrigin, setOriginX, setOriginY, setParent, setPosition, setPosition, setRotation, setScale, setScale, setScaleX, setScaleY, setSize, setTouchable, setUserObject, setVisible, setWidth, setX, setY, setZIndex, sizeBy, sizeBy, stageToLocalCoordinates, toBack, toFrontpublic Button(Skin skin)
public Button(Skin skin, java.lang.String styleName)
public Button(Actor child, Button.ButtonStyle style)
public Button(Button.ButtonStyle style)
public Button()
public Button(Drawable up)
public void setChecked(boolean isChecked)
public void toggle()
ChangeListener.ChangeEvent (if programmatic change
events are enabled), so can be used to simulate a button click.public boolean isChecked()
public boolean isPressed()
public boolean isOver()
public ClickListener getClickListener()
public boolean isDisabled()
isDisabled in interface Disableablepublic void setDisabled(boolean isDisabled)
isChecked() when clicked and will not fire a ChangeListener.ChangeEvent.setDisabled in interface Disableablepublic void setProgrammaticChangeEvents(boolean programmaticChangeEvents)
setChecked(boolean) and toggle() will not fire ChangeListener.ChangeEvent, event will be fired only
when user clicked the buttonpublic void setStyle(Button.ButtonStyle style)
public Button.ButtonStyle getStyle()
setStyle(ButtonStyle) is
called.public ButtonGroup getButtonGroup()
public void draw(Batch batch, float parentAlpha)
WidgetGroupWidgetGroup.validate() should be called to ensure the widget group is laid
out.public float getPrefWidth()
getPrefWidth in interface LayoutgetPrefWidth in class Tablepublic float getPrefHeight()
getPrefHeight in interface LayoutgetPrefHeight in class Tablepublic float getMinWidth()
getMinWidth in interface LayoutgetMinWidth in class Tablepublic float getMinHeight()
getMinHeight in interface LayoutgetMinHeight in class Table