java - How to make button changes repaint -during- method, not after? -


inside actionperformed method of jbutton, have following code:

btnlogin.settext("logging in..."); btnlogin.setpreferredsize(new dimension(110, 29)); btnlogin.setenabled(false);  //more stuff here, irrelevant 

this works, takes visual effect (is repainted) once method complete.

if in //more stuff here area have code takes long time complete, effects of btnlogin changes not take effect until code complete.

i have tried typing:

this.revalidate(); this.repaint();  

directly after first 3 lines, , multiple other solutions, try force damn thing repaint during method, no matter what, happens @ end!

another thing i've noticed if call joptionpane in middle of method, frame repaint (in background), that's interesting.

what is that's automatically happening in end of method need call make happen during method?

thanks in advance!

you're blocking swing event thread long-running code, , prevents swing drawing text changes. solution:

  • do long-running code in background thread such in swingworker's doinbackground method.
  • but make sure make swing calls on swing event thread.
  • read concurrency in swing tutorial learn details on swing event thread , threading issues.

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -