I an working on JavaFX 8 and SceneBuilder
. I created some radio buttons in the FXML File and specified a toggleGroup
name to a radio button list in that. So, now I want to get the toggleGroup
's selected radio button in my controller, do I need to make all the radio buttons again as fields in the controller, or just the toggleGroup
object will get me the selected radio button (the text of that radio button only, not the button object).
@FXML
ToggleGroup right; //I called it right in SceneBuilder.
later somewhere in method.
RadioButton selectedRadioButton = (RadioButton) right.getSelectedToggle();
String toogleGroupValue = selectedRadioButton.getText();