Call method in ChoiceBox

0

I created a ChoiceBox, where at each level selected, a method should be called; but the following happens, any selected item calls the method; how to make a condition, that is, depending on the item selected, calls a certain method. It follows a part of the code.

ChoiceBox cb = new ChoiceBox();
    cb.setId("btn_transparent_cb");
    cb.getItems().addAll("Nível 1", "Nível 2", "Nível 3", "Nível 4");
    //cb.getSelectionModel().selectFirst();


    cb.getSelectionModel().selectedIndexProperty()
    .addListener(new ChangeListener<Number>() {
      @Override
      public void changed(ObservableValue ov, Number value, Number new_value) {

        exemploMetodo();
      }
    });
    
asked by anonymous 07.05.2015 / 17:02

1 answer

0

I solved it, people; thank you. Here's the solution:

 cb.getSelectionModel().selectedIndexProperty().addListener((obs, old , newValue)->{
        switch(newValue.intValue()){
            case 0:
                metodoUm();
                break;
            case 1:
                metodoDois();
                break;
            case 2:
                metodoTres();
                break;
        }
    });
    
15.05.2015 / 22:59