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

public Class ButtonGroup<T extends Button>

extends Object
Class Inheritance
Imports
com.badlogic.gdx.utils.Array, .Null

Manages a group of buttons to enforce a minimum and maximum number of checked buttons. This enables "radio button" functionality and more. A button may only be in one group at a time.

The canCheck(Button, boolean) method can be overridden to control if a button check or uncheck is allowed.

Author
Nathan Sweet

Field Summary

Modifier and TypeField and Description
private final Array<T>
private Array<T>
private T
private int
private int
private boolean

Constructor Summary

AccessConstructor and Description
public
public
ButtonGroup(T... buttons)

Method Summary

Modifier and TypeMethod and Description
public void
add(T button)

public void
add(T... buttons)

protected boolean

Returns:

True if the new state should be allowed.
canCheck
(T button, boolean newState)

Called when a button is checked or unchecked.

public void
public Array<T>
public Array<T>
public T
getChecked()

Returns: The first checked button, or null.

public int
getCheckedIndex()

Returns: The first checked button index, or -1.

public void
remove(T button)

public void
remove(T... buttons)

public void
setChecked(String text)

Sets the first TextButton with the specified text to checked.

public void
setMaxCheckCount(int maxCheckCount)

Sets the maximum number of buttons that can be checked.

public void
setMinCheckCount(int minCheckCount)

Sets the minimum number of buttons that must be checked.

public void
setUncheckLast(boolean uncheckLast)

If true, when the maximum number of buttons are checked and an additional button is checked, the last button to be checked is unchecked so that the maximum is not exceeded.

public void
uncheckAll()

Sets all buttons' Button#isChecked() to false, regardless of setMinCheckCount(int).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

buttonsback to summary
private final Array<T> buttons
checkedButtonsback to summary
private Array<T> checkedButtons
lastCheckedback to summary
private T lastChecked
maxCheckCountback to summary
private int maxCheckCount
minCheckCountback to summary
private int minCheckCount
uncheckLastback to summary
private boolean uncheckLast

Constructor Detail

ButtonGroupback to summary
public ButtonGroup()
ButtonGroupback to summary
public ButtonGroup(T... buttons)

Method Detail

addback to summary
public void add(T button)
addback to summary
public void add(T... buttons)
canCheckback to summary
protected boolean canCheck(T button, boolean newState)

Called when a button is checked or unchecked. If overridden, generally changing button checked states should not be done from within this method.

Returns:boolean

True if the new state should be allowed.

clearback to summary
public void clear()
getAllCheckedback to summary
public Array<T> getAllChecked()
getButtonsback to summary
public Array<T> getButtons()
getCheckedback to summary
public T getChecked()
Returns:T

The first checked button, or null.

Annotations
@Null
getCheckedIndexback to summary
public int getCheckedIndex()
Returns:int

The first checked button index, or -1.

removeback to summary
public void remove(T button)
removeback to summary
public void remove(T... buttons)
setCheckedback to summary
public void setChecked(String text)

Sets the first TextButton with the specified text to checked.

setMaxCheckCountback to summary
public void setMaxCheckCount(int maxCheckCount)

Sets the maximum number of buttons that can be checked. Set to -1 for no maximum. Default is 1.

setMinCheckCountback to summary
public void setMinCheckCount(int minCheckCount)

Sets the minimum number of buttons that must be checked. Default is 1.

setUncheckLastback to summary
public void setUncheckLast(boolean uncheckLast)

If true, when the maximum number of buttons are checked and an additional button is checked, the last button to be checked is unchecked so that the maximum is not exceeded. If false, additional buttons beyond the maximum are not allowed to be checked. Default is true.

uncheckAllback to summary
public void uncheckAll()

Sets all buttons' Button#isChecked() to false, regardless of setMinCheckCount(int).