0

Im trying to use Radio buttons to make a choice and then once a choice has been selected, i can then go ahead and use a button to run a certain method matching the radio button that has been selected.

Below is an example of what i would like to do:

final ToggleGroup group = new ToggleGroup();
    RadioButton today = new RadioButton("Today");
    today.setToggleGroup(group);
    today.setSelected(true);
    RadioButton yesterday = new RadioButton("Yesterday");
    yesterday.setToggleGroup(group);
    RadioButton duration = new RadioButton("duration");
    duration.setToggleGroup(group);

    group.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
        @Override
        public void changed(ObservableValue<? extends Toggle> ov, Toggle t, Toggle t1) {

            RadioButton chk = (RadioButton)t1.getToggleGroup().getSelectedToggle(); // Cast object to radio button
            if(chk.getText() == "Today"){
              System.out.println("You've Selected Radio button 'Today'");
            }
            if(chk.getText() == "Yesterday"){
              System.out.println("You've Selected Radio button 'Yesterday'");
            } else{
                   System.out.println("You've Selected Radio button 'duration'");
            }
        }
    });

Thanks for your help :)

Sammson
  • 73
  • 1
  • 11

0 Answers0