File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes SIMPLE updating dialog!!! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "SIMPLE updating dialog!!!" Watch "SIMPLE updating dialog!!!" New topic
Author

SIMPLE updating dialog!!!

Lance Cash
Greenhorn

Joined: Oct 19, 2009
Posts: 17
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

Joined: Jun 13, 2009
Posts: 2153
    
    7
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

Joined: Oct 19, 2009
Posts: 17
Awesome, thanks. That got it.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: SIMPLE updating dialog!!!
 
Similar Threads
JProgressBar - Please Help
calling java class
Displaying a progress dialog
JProgressBar in Napkin look and feel is not working
waiting or loading screen in java