Class Button

  • All Implemented Interfaces:
    Cullable, Disableable, Layout
    Direct Known Subclasses:
    ImageButton, ImageTextButton, TextButton

    public class Button
    extends Table
    implements Disableable
    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.

    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.

    • Method Detail

      • setChecked

        public void setChecked​(boolean isChecked)
      • toggle

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

        public boolean isChecked()
      • isPressed

        public boolean isPressed()
      • isOver

        public boolean isOver()
      • getButtonGroup

        @Null
        public ButtonGroup getButtonGroup()
        Returns:
        May be null.
      • getBackgroundDrawable

        @Null
        protected Drawable getBackgroundDrawable()
        Returns appropriate background drawable from the style based on the current button state.
      • draw

        public void draw​(Batch batch,
                         float parentAlpha)
        Description copied from class: WidgetGroup
        If this method is overridden, the super method or WidgetGroup.validate() should be called to ensure the widget group is laid out.
        Overrides:
        draw in class Table
        parentAlpha - The parent alpha, to be multiplied with this actor's alpha, allowing the parent's alpha to affect all children.