title: Swing updating UI components while the job is running
body: <p>I am developing a swing applciation. In that I have a workflow of jobs to be done.</p>
  
  <p>I Am running these jobs in a for loop one after the other. The interesting thing is I have to update GUI status bar with the current job name running.</p>
  
  <p>I can not use SwingUtilities.invokeAndWait as it can not run on the dispatch thread which will be the currently running thread.</p>
  
  <p>I tried using SwingWorker since the jobs are running in a loop, the SwingWorker's doBackGrount() method will execute and will come out and gets the the next index to run the next job. In the done() of SwingWorker I have written code to update GUI with the status.</p>
  
  <pre><code>public class TestAction extends SwingWorker&lt;Boolean, Void&gt; {
  
      boolean executeThread = false;
  
      public TestAction() {
      }
  
      @Override
      protected Boolean doInBackground() throws Exception {
          executeThread = ExecuteWebServiceAction.webServiceExecution();
          return executeThread;
      }
  
      @Override
      protected void done() {
          try {
              boolean isOver = (boolean) get();
              if (isOver) {
                  MainApplication.getInstance().getFrame().setStatus(LangUtil.getString("cdsExecuteFinehed")
                          + " " + ((WebServiceTool) DrawingManager.getInstance().getCurrentTool()).getName());
                  FrameMain.jPanel6.repaint();
              }
          } catch (Interr`enter code here`uptedException ex) {
              Logger.getLogger(TestAction.class.getName()).log(Level.SEVERE, null, ex);
          } catch (ExecutionException ex) {
              Logger.getLogger(TestAction.class.getName()).log(Level.SEVERE, null, ex);
          }
      }
  }
  </code></pre>
  
  <p>And this is where am calling TestAction:</p>
  
  <pre><code>if (!WorkFlow.isIsWorkflow()) {
      SwingUtilities.invokeLater(
        new Runnable() {
          @Override
          public void run() {
            webServiceExecution();
          }
      });
  } else {
       new TestAction().execute();
  }
  </code></pre>