0

I want to update a progressbar while executing a heavy process. Using swingutil invokelater dont works. It gets updated upon it's finished.

...long lasting command ..
SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            searchDialog.setProgress( 60 );
          }
       });
...long lasting command ..
Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
user2147674
  • 2,319
  • 2
  • 14
  • 17
  • 2
    Don't block the EDT (Event Dispatch Thread). The GUI will 'freeze' when that happens. See [Concurrency in Swing](https://docs.oracle.com/javase/tutorial/uiswing/concurrency/) for details and the fix (a `SwingWorker` in this case). There is a [working example](http://stackoverflow.com/a/25338142/418556).. – Andrew Thompson Aug 05 '15 at 09:50
  • 1
    Use a `SwingWorker`, it has progress support via it's `PropertyChangeListener`, see [Worker Threads and SwingWorker](http://docs.oracle.com/javase/tutorial/uiswing/concurrency/worker.html) for more details – MadProgrammer Aug 05 '15 at 09:50
  • 1
    For [example](http://stackoverflow.com/questions/23125642/swingworker-in-another-swingworkers-done-method/23126410#23126410) – MadProgrammer Aug 05 '15 at 09:51
  • In the provided sample heavy work is done directly in the swingworker. I have a implemented a complex search with tree building and multiple threads. Would executing this search in the swingworker destroy my threadstructure? – user2147674 Aug 05 '15 at 09:57
  • 1
    @user2147674 SwingWorker is designated as bridge between WorkerThread and EDT (every methods expects doInBackground), doInBackground is place where can be invoked whatever you wrote about – mKorbel Aug 05 '15 at 11:37

0 Answers0