java - Changing a label during ActionEvent -


i trying enable/disable label when button pressed , want during event , not after it. can see below, try enable/disable 2 labels: lblkeyboard , lblgamepad.

they end running after "remotecontrol.run();" executed want happen before that. way can that?

thank you!

jbutton btngamepad = new jbutton("gamepad");         btngamepad.addactionlistener(new actionlistener() {             public void actionperformed(actionevent e) {                      if(cont_state == 0){                         if(remotecontrol.findgamepad() == true){                             cont_state = 1;                             game_status = "on";                         }                         else{                             game_status = "off";                             key_status = "on";                             joptionpane.showmessagedialog(null, "controller not found!");                             cont_state = 0;                         }                     }                      if(cont_state == 1){                              system.out.println("connected gamepad!");                         lblkeyboard.disable();                         lblgamepad.enable();                         frame.repaint();                         remotecontrol.run();                          cont_state = 0;                     }              }         }); 

actionevents run on edt responsible painting. once change labels state, swing issues request repaiting label. thing request posted on queue , executed once edt free and, can see, edt busy running code no repainting you! depending on nature of code, should consider using swingworker or moving remotecontrol.run() thread in

new thread(new runnable() {      @override      public void run() {           remotecontrol.run();      } }).start(); 

Comments

Popular posts from this blog

java - Spring Data JPA: Why findOne(id) executing delete query internally? -

python - Mongodb How to add addtional information when aggregating? -

java - Incorrect order of records in M-M relationship in hibernate -