swing - Java SwingUtilities.invokeLater -


.addactionlistener(new actionlistener(){         public void actionperformed (actionevent e){             try{                 ta.append("searching initiated at: "+datetime()+"\n");                 gui.setcursor(cursor.getpredefinedcursor(cursor.wait_cursor));                 task.execute();                 javax.swing.swingutilities.invokelater(new runnable() {                     public void run() {                         gui.setcursor(cursor.getpredefinedcursor(cursor.default_cursor));                     }                 });                 //enable next stage in yd process , disable executed functions                 clusan.setenabled(true);                 open.setenabled(false);                 statcl.setenabled(false);             }catch (exception ioe){                 }         }     }); 

hi there, having bit of pain last stage of application i've designed.

basically, when user clicks button, i'd cursor becomes 'waiting' version , once background process (task.execute) has completed, cursor returns normal.

the task.execute isn't in same class can't straight call of "gui.setcursor" because doesn't recognise gui variable.

not sure advice great

thanks :d

modify task's class takes gui constructor argument. way, when task completed, can invoke setcursor method.

you should use swingworker kind of thing.

edit :

here's how code of task should :

public class myswingworker extends swingworker<void, void> {      /**      * frame must have default cursor set       * @ end of background task      */     private jframe gui;      public myswingworker(jframe gui) {         this.gui = gui;     }      // ...      @override     protected void done() {         // done method called in edt.          // no need swingutilities.invokelater here         gui.setcursor(cursor.getpredefinedcursor(cursor.default_cursor));     } } 

Comments

Popular posts from this blog

Javascript line number mapping -

c# - Is it possible to remove an existing registration from Autofac container builder? -

php - Mysql PK and FK char(36) vs int(10) -