How to run event without initially clicking on radio button?

Asked

Viewed 191 times

0

How do I make a selection event from radioButton be started by default ?

I determined that mine radios buttons will call some methods when selected, I did within the initialize, however, the way this is, I have to click on the radio for it to perform, as I do, so that it already fires the event ? I have already tried to give a radio01.setSelected(true); but it only marks the radio 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
        });
}
  • If it will run without having to select the radio button then why put it as a select radio button event? Could not only without a normal boot event?

  • @Andersonhenrique he will change the components of the screen, he has to have event, because when selecting Radio2 will change the screen, without the event can not switch the screen by radio

  • Leaves the events and changes the screen on startup

  • There’s no other way, I’m changing the components on the screen, if it’s radio 1, it’s determined field, if it’s radio 2, it’s other fields.

  • tries using bind().

  • @Juliocesar could give me an example ?

  • in this example the button will be disable depending on whether or not the tableView contains data. btnSave.disableProperty().bind(Bindings.isEmpty(tbView.getItems()));

Show 2 more comments

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 vc must arrange the order of execution, remember, the order of execution of the codes is from left to right and from 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);
  • the result is the same, unfortunately.

  • where you want to run the radiobutton???

  • initialize, I leave it marked already, because I want the action to be executed without having to click, that on the first time

  • I just ran that code there and it works: @Override
 public void initialize(URL arg0, ResourceBundle arg1) {
 // TODO Auto-generated method stub 

 radio.selectedProperty().addListener((p, ov, nv) -> {
 //metódos
 if(nv)
 System.out.println("Pronto");
 });
 
 radio.setSelected(true); 

 }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.