How to run event without clicking radio button?

0

How do I make a select event for radioButton be started by default?

I have determined that my radios buttons will call some methods when selected, I did within initialize , however, in the way that this, I have to click on the radio for it to execute, as I do, so that it already trigger the event? I already tried to give radio01.setSelected(true); but it only marks the radius and does not trigger the event.

 public void initialize(URL location, ResourceBundle resources) {
        fisica.setSelected(true);

        radio01.selectedProperty().addListener((p, ov, nv) -> {
            //metódos
        });

        radio02.selectedProperty().addListener((p, ov, nv) -> {
            //metódos
        });
}
    
asked by anonymous 03.08.2017 / 13:54

1 answer

1

@ G1Wing will depend on what you want to do and on which object, you will use bind() . For your code to work you must sort the order of execution, remember, the order of execution of the codes is left to right and top to bottom.

    radio01.selectedProperty().addListener((p, ov, nv) -> {
        //metódos
        if(nv){
          //faz algo
        }              
    });

    radio02.selectedProperty().addListener((p, ov, nv) -> {
        //metódos
        if(nv){
          //faz algo
        } 
   });

   radio01.setSelected(true);
    
07.08.2017 / 23:12