java - jLabel's setText is not working even with SwingWorker -


i'm making jlabel display timer,so being updated every second , i'm updating of thread i'm using swingworker update jlabel not working. here code...

long pos=-1; private void jbutton1actionperformed(java.awt.event.actionevent evt) {                                                try     {         pos=...value of timer....         jlabel1.settext("in function");         jlabel3.settext("in function");         timer=new thread(new adsa());         timer.start();      }     catch(exception e)     {             system.out.println("exception caught");     } }                                          /**  *  */ public void run() {      try     {          system.out.println(pos);      while(pos!=0 && clip.isrunning())     {         label1.settext(string.valueof(pos));         system.out.println(pos);         pos--;         timer.sleep(1000);          swingworker worker = new swingworker() {              @override             public object doinbackground(){                  try                 {                 jlabel3.settext(string.valueof(pos));                 jlabel3.settext("ghfdxhc");                 label1.settext("hvgjh");                 system.out.println("zxc");                  return null;                 }                 catch(exception e)                 {                     return null;                 }              }         };         worker.execute();       }      }     catch(exception e)     {         system.out.println("error in run");     } } 

all println statements working,even one's inside swingworker jlabel not being updated, "in function" displayed on both labels , not changing. kindly suggest alternative method if possible...

for kind of work should use swing timer. swingworker ussually heavy task , don't block gui(event dispatch thread) cause run in differents thread.

im not sure if updating gui in doinbackground() reflected know , it's run in thread. ensure can

1) wrap call in swingutilities.invokelater(..)

2) using publish(..) , update here.

but recommend use task swing timer


Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -