• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Trouble with JProgressBar (not redrawing)

 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to Swing forum...
 
author
Posts: 73
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Adam,

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.

https://coderanch.com/t/340901/GUI/java/Swing-Performance-slow-swing

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

Scott Delap
ClientJava.com
Desktop Java Live
 
reply
    Bookmark Topic Watch Topic
  • New Topic