java - JLabel doesn't change back color -


part of function looks

jlabel2.setbackground(color.yellow); jlabel2.settext("status : idle");  boolean ok=cpu21.restartssh();  if(ok){     jlabel2.setbackground(color.green);     jlabel2.settext("status : run");     } 

before enter in function label green , run, when come in function doesn't chabge color yellow ( function restartssh executing 5-6 sec, during time labels doesn't change colors , captures ). make mistake in painting ?

  • make jlabel opaque can set background colour.
  • perform restartssh in separate thread, or gui won't respond events.

example:

final jlabel jlabel2 = new jlabel("hello"); jlabel2.setopaque(true); jlabel2.setbackground(color.yellow); jlabel2.settext("status : idle");  //perform ssh in separate thread thread sshthread = new thread(){     public void run(){         boolean ok=cpu21.restartssh();         if(ok){            //update gui in event dispatch thread            swingutilities.invokelater(new runnable() {                public void run() {                    jlabel2.setbackground(color.green);                    jlabel2.settext("status : run");                }            });         }     } }; sshthread.start(); 

(update: added call swingutilities.invokelater)


Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -