Reputation: 1323
I have the following piece of code:
GridPane gp = new GridPane();
// filling GridPane with other nodes...
RadioButton maschio = new RadioButton("M");
RadioButton femmina = new RadioButton("F");
final ToggleGroup tg = new ToggleGroup();
maschio.setToggleGroup(tg);
femmina.setToggleGroup(tg);
gp.add(tg, 1, 3);
I got an error on the last line saying: ToggleGroup cannot be converted to Node
.
What can I do? I also tried with Vbox, Hbox
but it didn't work.
Tried to Google but didn't find the solution. Any suggestions?
Upvotes: 1
Views: 5096
Reputation: 2949
ToggleGroup tg = new ToggleGroup();
RadioButton male = new RadioButton("Male");
male.setToggleGroup(tg);
RadioButton female = new RadioButton("Female");
female.setToggleGroup(tg);
HBox box = new HBox(20, male,female);
gp.add(box,1,3);
Toggle a control that can be toggled between selected and non-selected states. In addition, a Toggle can be assigned a ToggleGroup, which manages all assigned Toggles such that only a single Toggle within the ToggleGroup may be selected at any one time.
Upvotes: 2
Reputation: 1323
I found the following solution:
ToggleButton maschio = new RadioButton("M");
ToggleButton femmina = new RadioButton("F");
final ToggleGroup tg = new ToggleGroup();
HBox rbContainer = new HBox(maschio, femmina);
maschio.setToggleGroup(tg);
femmina.setToggleGroup(tg);
gp.add(rbContainer, 1, 3);
Is it ok? or you have better solutions?
Upvotes: 0