Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Indeterminate progressbar freezes when executing thread

843807Apr 12 2010 — edited Aug 19 2010
Hi people,

Here is my problem.
In my GUI application, at some point the user needs to perform a time consuming application. I want to tell the user that the task is performing as it is supposed to by displaying an undeterminate progressbar. However, when the task is being executed, the progress bar just freezes, until the task is finished. This particular task involves the use of an external process (i.e. .exe file).

To remedy this, I launch a separate thread to perform my task, using SwingWorker, which, as I understand it, is a class designed for exactly this sort of thing. But it does not work! I spent a lot of time trying to get this problem solve but with no success. I also tried to put the the task in a "conventional" thread, but it always result in the same behavior. Here is some of my code, so someone can maybe see what am I doing wrong. In that code, the progressDialog displays a progressbar set at indeterminate(true);

Since I successfully used the code below to perform more simple tasks (like reading files and extracting lines from it), I am wondering if the use of an external .exe might be the problem here.

Cheers,


...
progressDialog = new StatusJDialog(new javax.swing.JFrame(), false);
progressDialog.setVisible(true);
               
task = new Task();
task.execute();

...
class Task extends SwingWorker<Void, Void> {
/*
* Main task. Executed in background thread.
*/
@Override
//None GUI stuff goes here.
public Void doInBackground()  {
       try {
                Thread.sleep(100);
                WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
                    public void run() {
                        //Do time consuming task using external .exe here...
                    }
                });
            } catch (InterruptedException ignore) {}
            return null;
        }
        
        /*
         * Executed in event dispatch thread
         */
@Override
public void done() {
    Toolkit.getDefaultToolkit().beep();
    progressDialog.setVisible(false);
   }
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 16 2010
Added on Apr 12 2010
8 comments
957 views