Documentation

Trace: Using ActionGroup

(applications)

Using ActionGroup

If you have multiple radio/toggle buttons in your UI and have the use-case that only one button should be selected, the ActionGroup is a perfect match. The ActionGroup handles a set of radio/toggle buttons and ensures that only one button in the group is selected.

The ActionGroup has an action event that triggers notifications when the selection has been changed.

UIRadioButton butHLeft = new UIRadioButton("Left");
UIRadioButton butHCenter = new UIRadioButton("Center");
UIRadioButton butHRight = new UIRadioButton("Right");
UIRadioButton butHStretch = new UIRadioButton("Stretch");
 
ActionGroup buttonGroup = new ActionGroup(butHLeft, butHCenter, butHRight, butHStretch);

The selected button can be changed programmatically by index

buttonGroup.setSelectedIndex(1); // Choose the selected index

or by button instance

buttonGroup.setSelectedButton(butHLeft); // Choose the selected button


Use eventAction to get notifications about selection changes:

buttonGroup.eventAction().addListener(this, “doSelectionChanged”);
This website uses cookies for visitor traffic analysis. By using the website, you agree with storing the cookies on your computer.More information