A ToggleGroup
is used to manage the RadioButton
s so that just one in each group can be selected at each time.
Create a simple ToggleGroup
like following:
ToggleGroup group = new ToggleGroup();
After creating a Togglegroup
it can be assigned to the RadioButton
s by using setToggleGroup(ToggleGroup)
. Use setSelected(Boolean)
to pre-select one of the RadioButton
s.
RadioButton radioButton1 = new RadioButton("stackoverlow is awesome! :)");
radioButton1.setToggleGroup(group);
radioButton1.setSelected(true);
RadioButton radioButton2 = new RadioButton("stackoverflow is ok :|");
radioButton2.setToggleGroup(group);
RadioButton radioButton3 = new RadioButton("stackoverflow is useless :(");
radioButton3.setToggleGroup(group);