stevek stevek - 3 days ago 4
Java Question

JavaFX ToggleButton, is there a way to pass if its clicked as a "status"?

Is there a way for me to pass the status of toggle button(s) as a argument/parameter? I would like for it to work like this scenario:

1) Press a button.
2) Press GO!
3) Depending on which button is pressed, it is passed so there are different outcomes when I press GO!


yab yab

here's some code for reference, if it is not what you want, let me know.

public class Foo extends Application{
  public void start(Stage primaryStage) throws IOException{
    ToggleGroup group = new ToggleGroup();

    ToggleButton tb1 = new ToggleButton("ToggleButton 1");
    ToggleButton tb2 = new ToggleButton("ToggleButton 2");
    ToggleButton tb3 = new ToggleButton("ToggleButton 3");


    Button btn = new Button("GO");
    btn.setOnAction(new EventHandler<ActionEvent>(){
      public void handle(ActionEvent event){
        Toggle selectedTogger = group.getSelectedToggle();
        if(selectedTogger == tb1){
          //outcome 1 (ToggleButton1 selected)

        }else if(selectedTogger == tb2){
          //outcome 2 (ToggleButton2 selected)

        }else if(selectedTogger == tb3){
          //outcome 3 (ToggleButton3 selected)

          //outcome 4 (No ToggleButton selected)


    VBox vbox = new VBox();
    vbox.getChildren().addAll(tb1, tb2, tb3, btn);

    primaryStage.setScene(new Scene(vbox));;

  public static void main(String[] args){