• Post Reply Bookmark Topic Watch Topic
  • New Topic

Threading a GUI progress bar

 
John Forsyth
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am working on a program that involves long database queries. What I would like to do is have a JProgressBar in indeterminate mode to run during this query to show that work is still occurring.

I have managed to get a thread to run. It will run during the query and update an internal counter (ie, i++), but the progress bar freezes until after the query is finished.

Is there a way to make sure the GUI is updated/continues to run during the thread?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, welcome to the ranch!

I bet you ran into the same thing that prompted this post in the general forums. When you do work in another thread, you can't update the UI from that thread. Well, you can try but the results don't paint promptly or cleanly sometimes.

HERE is the middle of the Sun tutorial on the subject. You'll need to learn to use SwingUtilities to invoke a Runnable that does the actual UI update. It takes a couple extra classes and method calls, but it's only tricky the first time.

Show us what you make!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!