1

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?

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
bog
  • 1,323
  • 5
  • 22
  • 34

2 Answers2

2
    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.

Reegan Miranda
  • 2,879
  • 6
  • 43
  • 55
0

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?

bog
  • 1,323
  • 5
  • 22
  • 34
  • Ref ToggleButton http://stackoverflow.com/questions/15819242/how-to-make-a-button-appear-to-have-been-clicked-or-selected-javafx2 – Reegan Miranda Jan 29 '15 at 11:47