Reputation: 863
In the following code, I am running a progressbar. The progressbar is shown, however it is doing nothing.
Once I set setIndeterminate(false);
, it is working as expected (it updates every 500 ms and increment by 1).
How can I change that code, to show a indeterminate progressbar?
class ProgressWorker extends SwingWorker<Void, String> {
JProgressBar progressBar;
public ProgressWorker(JProgressBar progressBar) {
this.progressBar = progressBar;
this.progressBar.setVisible(true);
this.progressBar.setIndeterminate(true);
this.progressBar.setValue(0);
progressBar.setString("Loading...");
// This is the important line
progressBar.setStringPainted(true);
}
@Override
protected Void doInBackground() {
while (StatusBar.this.showIndeterminateProgress)
try {
this.progressBar.setValue(this.progressBar.getValue()+1);
System.out.println("showing progress");
publish("progress..");
Thread.sleep(500);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
@Override
protected void done() {
// this.progressBar.setVisible(false);
}
Somewhere I call that with
new ProgressWorker(progress).execute();
Let me emphasize that above code works fine for a determinable progressbar. I don't understand why it won't do for an indeterminate progressbar.
Upvotes: 0
Views: 37