so I want to make a set of radio buttons. If I press a radio button a new set of text fields will pop up. What piece of code do I use to achieve this? I am using Java by the way and just want to use JavaFX to achieve my objective. I've heard of using a certain command of showVisible but I'm not sure if that will work?
Asked
Active
Viewed 350 times
0
-
2[Possible duplicate](http://stackoverflow.com/questions/32424915/how-to-get-selected-radio-button-from-togglegroup), please before asking try to google your question. – lmiguelvargasf Nov 30 '16 at 23:05
-
What have you tried so far? As I got the impression that you are new to javafx, why not following a few tutorials on it? – n247s Nov 30 '16 at 23:20
-
Yeah, I'm new just taking a intro to java course at college – C Hobbs Jan 01 '17 at 02:26
1 Answers
1
Radio button:
ToggleGroup group = new ToggleGroup();
RadioButton rb1 = new RadioButton("RadioButton1");
rb1.setUserData("RadioButton1");
rb1.setToggleGroup(group);
rb1.setSelected(true);
and when you want to change the text do this:
group.selectedToggleProperty().addListener(new ChangeListener<Toggle>(){
public void changed(ObservableValue<? extends Toggle> ov, Toggle old_toggle, Toggle new_toggle) {
if (group.getSelectedToggle() != null) {
// Do something here with the radioButton
}
}
});

codeNinjaBro
- 78
- 10
-
Better make sure to add the listener before selecting the `RadioButton`, since otherwise this could lead to unexpected behavior. (If a user selects another toggle and then selects the original toggle again the effects of the code in the listener are only applied the second time...) – fabian Dec 01 '16 at 08:54
-
At this point once the radio button is selected, all you have to do is set the visibility of the textfields to true; – SedJ601 Dec 01 '16 at 14:29