Class ButtonGroup<T extends Button>
- java.lang.Object
-
- com.badlogic.gdx.scenes.scene2d.ui.ButtonGroup<T>
-
public class ButtonGroup<T extends Button> extends java.lang.Object
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.
-
-
Constructor Summary
Constructors Constructor Description ButtonGroup()
ButtonGroup(T... buttons)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(T button)
void
add(T... buttons)
protected boolean
canCheck(T button, boolean newState)
Called when a button is checked or unchecked.void
clear()
Array<T>
getAllChecked()
Array<T>
getButtons()
T
getChecked()
int
getCheckedIndex()
void
remove(T button)
void
remove(T... buttons)
void
setChecked(java.lang.String text)
Sets the firstTextButton
with the specified text to checked.void
setMaxCheckCount(int maxCheckCount)
Sets the maximum number of buttons that can be checked.void
setMinCheckCount(int minCheckCount)
Sets the minimum number of buttons that must be checked.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.void
uncheckAll()
Sets all buttons'Button.isChecked()
to false, regardless ofsetMinCheckCount(int)
.
-
-
-
Constructor Detail
-
ButtonGroup
public ButtonGroup()
-
ButtonGroup
public ButtonGroup(T... buttons)
-
-
Method Detail
-
add
public void add(T button)
-
add
public void add(T... buttons)
-
remove
public void remove(T button)
-
remove
public void remove(T... buttons)
-
clear
public void clear()
-
setChecked
public void setChecked(java.lang.String text)
Sets the firstTextButton
with the specified text to checked.
-
canCheck
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:
- True if the new state should be allowed.
-
uncheckAll
public void uncheckAll()
Sets all buttons'Button.isChecked()
to false, regardless ofsetMinCheckCount(int)
.
-
getCheckedIndex
public int getCheckedIndex()
- Returns:
- The first checked button index, or -1.
-
setMinCheckCount
public void setMinCheckCount(int minCheckCount)
Sets the minimum number of buttons that must be checked. Default is 1.
-
setMaxCheckCount
public void setMaxCheckCount(int maxCheckCount)
Sets the maximum number of buttons that can be checked. Set to -1 for no maximum. Default is 1.
-
setUncheckLast
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.
-
-