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);
}
}