Jprogressbar not updating

See the Swing Worker documentation, example at the top:

Ideally you'd update your Bulk Processor in the do In Background method of the Swing Worker, and that would call set Progress, and the j Progress Bar would be listening for those progress updates as in the example.

You need to get your image loading code OFF the EDT...

If you block this thread (doing time consuming tasks, I/O, etc...) you will stop it from processing input from the user and dispatching repaint requests to the components - so nothing will update and your application will look like it's hung...

Now that we've identified the problem, how do we fix it?

The answer in your case will depend on your program requirements and your comfort level with threads.

jprogressbar not updating-15jprogressbar not updating-41jprogressbar not updating-66jprogressbar not updating-22

Those with sharp eyes will also notice that the button "Do Something" remains depressed until the loop is complete. The code that paints the GUI and events generated by the GUI are executed on a single thread, called the "event-dispatching thread".

While we are using it, the event-dispatching thread is unable to update the GUI.

Hence the JProgress Bar remaining at position 0 and the JButton appearing to be depressed until the for loop completes.

I have tested this method and it updates correctly.

The issue is that the progress bar will not update until the files are finished processing, and then it will jump to 100%.

Leave a Reply