Forums Register Login
Trouble with JProgressBar (not redrawing)

I've written a program that is transferring records from one database to another. I have a main class, a GUI builder class, and a seperate class for each table I transfer. So, the main class sets stuff up, calling the GUI class, and the GUI class then calls upon each table class to handle the transfers (You select tables to transfer with checkboxes, and hit a button to begin).

I have two JProgressBars, one that shows the progress on the current table, and one that shows total progress. So, if I want to transfer two tables (each with 1000 records) then the top bar goes to 1000, and then resets when the second table is started, while the bottom bar will go all the way to 2000.

I set the maximum values for the bars in the GUI class, and have a static method for updating the values, which is then called per record in each respective table class.

I hope this has made sense thus far...

The problem is, when I run the program, the GUI window seems to lose focus while the queries and updates run, and so the ProgressBars don't repaint. These are no small tasks, each table transferred takes a number of minutes to complete, so I'd like the user to be able to see where he stands.

Am I overlooking something obvious?

Thanks in advance.
Do you run your long tasks on their own threads? If so, look into SwingUtilities invokeAndWait() or invokeLater() methods. Create a runnable object that updates the progress bar and pass that object to one of those methods. I had a similar GUI that only updated the progress info if I resized the window until I found SwingUtilities.
Moving to Swing forum...

Sounds like a Event Dispatch Thread issue. As the other post says, I'd check if you task are running on the EDT. If you check out this post from a few days ago, you will see I posted some information on how to do this.


If nothing else you might have to manually call revalidate()/repaint() when the progress bar is updated.

Scott Delap
Desktop Java Live
Wink, wink, nudge, nudge, say no more ... https://richsoil.com/cards

All times above are in ranch (not your local) time.
The current ranch time is
Nov 22, 2017 15:03:48.