Tutorial by Examples

Radio Buttons allow you to let the user choose one element of those given. There are two ways to declare a RadioButton with a text besides it. Either by using the default constructor RadioButton() and setting the text with the setText(String) method or by using the other constructor RadioButton(Stri...
A ToggleGroup is used to manage the RadioButtons 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 RadioButtons by using setToggleGroup(ToggleGrou...
Typically, when one of the RadioButtons in a ToggleGroup is selected the application performs an action. Below is an example which prints the user data of the selected RadioButton which has been set with setUserData(Object). radioButton1.setUserData("awesome") radioButton2.setUserData(&q...
Let's say the second RadioButton out of three is pre-selected with setSelected(Boolean), the focus is still at the first RadioButton by default. To change this use the requestFocus() method. radioButton2.setSelected(true); radioButton2.requestFocus();

Page 1 of 1