I have two threads. One is running the business logic from my BulkProcessor class which updates the BulkProcessor.getPercentComplete() variable:
public void run(){
new SwingWorker<Void,Void>() {
protected Void doInBackground() throws Exception {
BulkProcessor.main(jTextField0.getText(), jTextField1.getText());
return null;
};
}.execute();
}
My other thread is what updates the jProgressBar's value in my BulkGUI class:
public void update(){
jProgressBar0.setStringPainted(true);
jProgressBar0.repaint();
new SwingWorker<Void,Integer>() {
protected Void doInBackground() throws Exception {
do
{
percentComplete = BulkProcessor.getPercentComplete();
publish(percentComplete);
Thread.sleep(100);
} while(percentComplete < 100);
return null;
}
@Override
protected
void process(List<Integer> progress)
{
jProgressBar0.setValue(progress.get(0));
}
}.execute();
}
I call the two threads when the Process button is clicked:
private void jButton0ActionActionPerformed(ActionEvent event) {
run();
update();
}
Running this the first time works exactly as expected. However selecting the Process button a second time has no affect on the jProgressBar. The local variable percentComplete in the update thread remains at 100, and does not update as it does the first run. I tested the percentComplete variable from the BulkProcessor class, and this variable does in fact update as expected. So for some reason the thread is not fetching the update values using BulkProcessor.getPercentComplete() the second time the thread is called. Anybody have any insight on this? Any help is much appreciated.