java - Swing update puzzle -


i have jtree nodes representing images user can call , view. takes images 4 or 5 seconds load. ideally, wait cursor show while user waiting , node selected in tree selected. however, i'm find user clicks on node, nothing appears happen , image appears , node selected (the wait cursor never appears or more appears briefly , disappears immediately. i've tried repainting both tree , applet try force behavior happen in sequence want. far, i've not had luck. suggestions? here section of swing code giving me problems:

 thisapplet.setcursor(new cursor(cursor.wait_cursor));  selectdocumenttreeleaf(); // jtree nodes representing images                    tree.repaint();  thisapplet.repaint();  tree.setenabled(false); //disabled users don't keep clicking on it.     result = createimage(queue.q[pointer].currentpage); //where image fetched                thisapplet.setcursor(new cursor(cursor.default_cursor)); 

i think pace on money. use background thread such swingworker , problems solved. please check out concurrency in swing more details on edt , thread problems. e.g.,

  thisapplet.setcursor(new cursor(cursor.wait_cursor));   selectdocumenttreeleaf();    tree.repaint();   thisapplet.repaint();   tree.setenabled(false);     new swingworker<image, void>(){      @override      protected image doinbackground() throws exception {         return createimage(queue.q[pointer].currentpage);;      }       @override      protected void done() {         try {            result = get();            thisapplet.setcursor(new cursor(cursor.default_cursor));            tree.setenabled(true);         } catch (interruptedexception e) {            e.printstacktrace();         } catch (executionexception e) {            e.printstacktrace();         }      }   }.execute(); 

Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -