This code actually works, but I think it could be written differently. I have a custom JDialog that I am using to display an indeterminate progress bar. Right I set the title, visibility, and location within my while loop. While this works, this I would think that it should be displayed right under where I create my worker, but when I do that it gives me an illegal start of type error. Any ideas? Thanks.
SwingWorker worker = new SwingWorker<Void, Void>(){
//I am thinking this should work, but it doesn't
// Progress.setTitle("Loading Repository");
// Progress.setLocationRelativeTo(null);
// Progress.setVisible(true);
@Override
protected Void doInBackground() throws Exception {
while (runLoad.getState() != Thread.State.TERMINATED && !isCancelled()) {
try {
Progress.setTitle("Loading Repository");
Progress.setLocationRelativeTo(null);
Progress.setVisible(true);
synchronized (this) {
Thread.sleep(2000);
}
} catch (InterruptedException e) {
JOptionPane.showMessageDialog(null,
"Process interrupted: " + e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE);
}
}
return null;
}
@Override
public void done() {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
Progress.setVisible(false);
Progress.dispose();
}
});
}
};
worker.execute();