0

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

}

Naz_Jnr
  • 570
  • 1
  • 7
  • 17
  • How are you calling this method? Using `execute()` or `run()`? – Ferrybig Feb 08 '16 at 10:04
  • I am using execute() – Naz_Jnr Feb 08 '16 at 10:05
  • @user7378 Can you show the code where you call this class? – Ferrybig Feb 08 '16 at 10:06
  • 3
    *"The GUI remains stuck until the doInBackground operation is completed. No intermediate update of GUI happens"* Are you calling `get` in the EDT? *"My Question Please, why is this happening and how do I get around it?"* - Without a runnable example, it's going to be impossible to know – MadProgrammer Feb 08 '16 at 10:06

0 Answers0