I am trying to update my Swing GUI using the Swing Worker process() method. In other words, the calculation goes on in the doInBackground() method, publishes its result and then the process() method effects the change on the GUI.
My Challenge The GUI remains stuck until the doInBackground operation is completed. No intermediate update of GUI happens.
Also, the the done() method is fired even before i see the contents of the process() method
My Question Please, why is this happening and how do I get around it?
class SwingWorkerThread extends SwingWorker<String, String> {
@Override
protected String doInBackground() throws Exception {
String Pub = "Default";
for (int i = 0; i < 2000; i++) {
Pub = String.valueOf(i);
publish(Pub);
Thread.sleep(200);
}
return Pub;
}
@Override
protected void process(List<String> chunks) {
for (String number : chunks) {
MainFrame.TextArea.append(number + "\n");
System.out.println(number);
}
}
@Override
protected void done() {
System.out.println("Done Here");
}
}