Class ButtonGroup
- All Implemented Interfaces:
ActionSource<ActionEvent>
This class is used to create a multiple-exclusion scope for
com.codename1.ui.RadioButton.
Creating a set of com.codename1.ui.RadioButton components with the same ButtonGroup object
means that only one com.codename1.ui.RadioButton can be selected among those within
the specific ButtonGroup.
CheckBox cb1 = new CheckBox("CheckBox No Icon");
cb1.setSelected(true);
CheckBox cb2 = new CheckBox("CheckBox With Icon", icon);
CheckBox cb3 = new CheckBox("CheckBox Opposite True", icon);
CheckBox cb4 = new CheckBox("CheckBox Opposite False", icon);
cb3.setOppositeSide(true);
cb4.setOppositeSide(false);
RadioButton rb1 = new RadioButton("Radio 1");
RadioButton rb2 = new RadioButton("Radio 2");
RadioButton rb3 = new RadioButton("Radio 3", icon);
new ButtonGroup(rb1, rb2, rb3);
rb2.setSelected(true);
hi.add(cb1).add(cb2).add(cb3).add(cb4).add(rb1).add(rb2).add(rb3);
-
Constructor Summary
ConstructorsConstructorDescriptionCreates a new instance of ButtonsGroupButtonGroup(RadioButton... rb) Adds all the radio buttons to the group -
Method Summary
Modifier and TypeMethodDescriptionvoidadd(RadioButton rb) Adds a RadioButton to the groupvoidAdds an action listener to all the buttons in the groupvoidaddAll(RadioButton... rb) Adds the RadioButtons to the groupvoidClears the selection such that none of the buttons in the ButtonGroup are selected.intReturns the number of buttons in the group.getRadioButton(int index) Returns the radio button at the given group indexReturn the selected radio button within the groupintReturn the index of the selected button within the groupbooleanReturns whether a radio button in the group is selected.voidremove(RadioButton rb) removes a RadioButton from the groupvoidRemoves an action listener from all the buttons in the groupvoidsetSelected(int index) Sets the selected Radio button by indexvoidSelects the given radio button
-
Constructor Details
-
ButtonGroup
public ButtonGroup()Creates a new instance of ButtonsGroup -
ButtonGroup
Adds all the radio buttons to the group
Parameters
rb
-
-
Method Details
-
addAll
Adds the RadioButtons to the group
Parameters
rb: a RadioButtons to add
-
add
Adds a RadioButton to the group
Parameters
rb: a RadioButton to add
-
remove
removes a RadioButton from the group
Parameters
rb: a RadioButton to remove
-
clearSelection
public void clearSelection()Clears the selection such that none of the buttons in the ButtonGroup are selected. -
getButtonCount
public int getButtonCount()Returns the number of buttons in the group.
Returns
number of radio buttons in the group
-
isSelected
public boolean isSelected()Returns whether a radio button in the group is selected.
Returns
true if a selection was made in the radio button group
-
getSelectedIndex
public int getSelectedIndex()Return the index of the selected button within the group
Returns
the index of the selected button within the group
-
getSelected
Return the selected radio button within the group
Returns
the selected radio button within the group
-
setSelected
Selects the given radio button
Parameters
rb: the radio button to set as selected
-
setSelected
public void setSelected(int index) Sets the selected Radio button by index
Parameters
index: the index of the radio button to mark as selected
-
getRadioButton
Returns the radio button at the given group index
Parameters
index: offset within the group starting with 0 and no larger than getButtonCount()
Returns
the radio button instance
-
addActionListener
Adds an action listener to all the buttons in the group
Parameters
al: the listener
- Specified by:
addActionListenerin interfaceActionSource<ActionEvent>
-
removeActionListener
Removes an action listener from all the buttons in the group
Parameters
al: the listener
- Specified by:
removeActionListenerin interfaceActionSource<ActionEvent>
-