Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SIMPLE updating dialog!!!

 
Lance Cash
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok...I wrote a simple test class to illustrate a problem I'm having. Here's the flow:

1. User clicks button on frame
2. This starts some long running process and opens a dialog to show the progress
3. When the process completes, status text on the dialog gets updated

The problem is that the components just don't get refreshed like they should. My guess is that there is some kind of threading issue going on? I'm not sure at this point. Any help is GREATLY appreciated. Thanks in advance. Lance.



By the way, it may appear to work the first time you run it because the text will change from blank to "Not to be". It should be blank => "To be" => "Not to be". Also, if you dispose the dialog and click the button again, nothing will change. It is "Not to be" when you click it and "Not to be" after the process runs. Thanks, again. Lance.
 
Rob Camick
Ranch Hand
Posts: 2559
9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that there is some kind of threading issue going on?


Correct, the problem is that you are NOT using Threads. You want your long running task to execute in a separate Thread.



Code in any event listener already executes on the Event Dispatch Thread (EDT) automatically. The invokeLater is redundant.

Instead you should be starting a separate Thread. Then if any code in that thread needs to updated the GUI you can use invokeLater(...) to add that piece of code to the EDT.

Read the section from the Swing tutorial on Concurrency for more information.
 
Lance Cash
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Awesome, thanks. That got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic