Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

ProgressMonitor and threading ...  RSS feed

 
Tom Diamond
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Does the ProgressMonitor run on its own thread?
Here is the situation : I want to monitor a long task so I use a ProgressMonitor If I call this task before the rest of the GUI is built then there is no problem. But if I call the task afterwards then the dialog of the monitor comes out (empty - no progress bar, no labels) and everything freeses until the task is finished.
Did I miss anything? Here is some code :

Tnx,
Tom.
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No... the process that the progress bar is monitoring has to run in its own thread... Take a look at the Sun tutorial on progress bars.
 
John Dale
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like everythink else in Swing except where the documentations says otherwise, ProgressMonitor and all its methods must run on the Swing dispatch thread.
If you have some other thread that needs to update the progress monitor via setProgress(), etc., it needs to be sure that the setProgress() etc. calls are done on the Swing dispatch thread. There are several ways to go about this, depending how your work is spit over threads. One way is call setProgress from a Swing Timer action, which, like all actions, runs on the Swing dispatch thread; I think this is what is in the tutorial. Another way is to call setProgress() via SwingUtilities.invokeLater().
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!