java - What is preventing my progress bar from updating? -


i'm writing small function update progressbar , jlabel base on weighted random integers. thread sleeping correctly , random values coming through, however, progress bar , jlabel not updating.

it leaving gui unresponsive. isn't locking gui (i'm able click buttons, doesn't execute functions associated buttons).

throwing print statement in run() method not printed out. i'm thinking never gets in there.

here method far:

private void updateprogressbar(int max) {     final int maxdiamonds = max;     int = 0;     while(i <= max) {         //get random obstacle found         final obstacle o = obstacle.next();         system.out.println("obstacle: " + o.getname());         //get random number of diamonds obstacle         int numdiamonds = integer.parseint(numfounddiamonds.next());         system.out.println("number of diamonds: " + numdiamonds);         //set currentvalue progress bar         final int currentvalue = i;          for(int j = o.getremovaltime(); j >= 0; j--) {             final int rsecs = j;             system.out.println("time remaining remove: " + rsecs);             try {                 swingutilities.invokelater(new runnable() {                     public void run() {                         progressbar.setstring(currentvalue + "/" + maxdiamonds);                         statuslabel.settext("found " + o.getname() + ". removing: " + rsecs + " s remaining.");                     }                 });                 java.lang.thread.sleep(1000);             } catch (interruptedexception e) {                 joptionpane.showmessagedialog(this, e.getmessage());             }         }         += numdiamonds;       }  } 

perhaps i'm overlooking simple.

i can provide more code regarding other classes used, feel issue lies in code provided.

you're calling thread.sleep(...) on swing event thread put whole swing thread , application sleep. use background thread such swingworker.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -