title: SwingWorker done() method seemingly not called? SwingWork not cancelled or blocked either though, Not using publish/process methods
body: <p><strong>My Question:</strong> Why is my SwingWorker, which seems to simply execute my tool in it's thread, and exit just fine from the <em>doInBackground()</em> method (no use of <em>cancel()</em> SwingWorker method), not call the done() method so my progress bar and label may be cleaned up when the tool is done in <em>doInBackground()</em>?</p>
  
  <p>I'm pretty new to SwingWorkers, but I'm picking them up quickly and they make a lot of sense when needing to run threaded processes and still update a GUI.  I ended up finding the SwingWork class when I needed to add a progress bar to my Wizard-like GUI.  The GUI collects some data from the user, and then runs a tool that I have already tested and have working on a file based on that data.</p>
  
  <p>I have my basic SwingWorker that calls my tool(which is called from it's own thread):</p>
  
  <pre><code>private class DeIDTask extends SwingWorker&lt;Void, Void&gt; {
  
      private DeIdentifier deidentifier;
      boolean processing = true;
  
      DeIDTask(DeIdentifier deid) {
          this.deidentifier = deid;
      }
  
      /*
       * Main task. Executed in background thread.
       */
      @Override
      protected Void doInBackground() throws Exception {
          // Initialize Progress
          setProgress(0);
          //Sleep for at least one second to simulate "startup".
          try {
              Thread.sleep(1000 + new Random().nextInt(2000));
          } catch (InterruptedException ignore) {}
          // Do Processing
          Thread procThread = new Thread(new DeIdentifierProcessThread(deidentifier));
          procThread.start();
          while(procThread.isAlive()) {
              try {
                  // try to join every half a second
                  procThread.join(500);
                  setProgress(deidentifier.getProcessProgress());
              } catch (InterruptedException e1) {
                  e1.printStackTrace();
              }               
          }
  
          processing = false;
  
          // Do Output Flushing
          Thread outputThread = new Thread(new DeIdentifierOutputThread(deidentifier));
          outputThread.start();
          while(outputThread.isAlive()) {
              try {
                  // try to join every quarter second
                  procThread.join(250);
                  setProgress(deidentifier.getOutputProgress());
              } catch (InterruptedException e1) {
                  e1.printStackTrace();
              } 
          }
  
          return null;
      }
  
      /*
       * Executed in event dispatching thread
       */
      @Override
      protected void done() {
          lblProgress_deid.setText("Done.");
          progressBar_deid.setStringPainted(false);
          progressBar_deid.setIndeterminate(false);
          button_65.setEnabled(true);
      }
  }
  </code></pre>
  
  <p>Please note that this SwingWorker class <strong>only</strong> implements the <em>doInBackground()</em> and <em>done()</em> method.  I do not in any way call <em>cancel()</em>, which I know would have the ability to execute the <em>done()</em> method before the <em>doInBackground()</em> method was done.</p>
  
  <p>My thought was that maybe my SwingWork wasn't executed properly and thus my <em>done()</em> method couldn't find the Event Dispatch Thread.  I found such an answer <a href="http://www.dreamincode.net/forums/topic/248687-done-not-being-executing-in-swingworker/" rel="nofollow noreferrer" title="here">here</a>, but the way the answerer answered the question was really simplistic for my much more complex GUI and doesn't really explain how creating a JFrame in the main method makes that a Swing application that the SwingWork is explicitly connected to.  It doesn't seem to me that you need to do something special to connect the SwingWorker to the Swing Components.  </p>
  
  <p>I have created a functioning GUI, and the place that my GUI calls the SwingWorker is from a JButton:</p>
  
  <pre><code>btnStartDeidentification = new JButton("Start De-Identification");
      btnStartDeidentification.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
              // Disable clicking of the button
              progressBar_deid.setIndeterminate(true);
              btnStartDeidentification.setEnabled(false);
  
              task_deid = new DeIDTask(deidentifier);
              task_deid.addPropertyChangeListener(new PropertyChangeListener() {
  
                  @Override
                  public void propertyChange(PropertyChangeEvent evt) {
                      int progress = task_deid.getProgress();
                      System.out.println("Progress is: " + progress);
                      progressBar_deid.setIndeterminate(false); 
                      progressBar_deid.setString(null);
                      progressBar_deid.setValue(progress);
                      progressBar_deid.setStringPainted(true);
                      lblProgress_deid.setText("Processing Records (Current/Total): " + deidentifier.getCurrentLineNumber() + "/" + deidentifier.getNumberOfLinesInFile());
  
                  }
  
              });
              task_deid.execute();
          }
      });
  
      btnStartDeidentification.setBounds(107, 195, 200, 29);
      panel_runDeIDTool_23.add(btnStartDeidentification);
  </code></pre>
  
  <p>My next thought is that maybe because I actually initialize and execute the SwingWork task_deid from <strong>inside</strong> my <em>actionPerformed()</em> method that the <em>done()</em> method is for some reason not finding the EDT.  But this question <a href="https://stackoverflow.com/questions/23195039/swingworker-done-method-not-called">here on SO</a>, very similarly named to my own question, has an example of a SwingWorker being called from inside a <em>changeListener()</em>.  And the answerer states that that <em>changeListener()</em> is part of the EDT.  I haven't worked with a changeListener in a GUI yet, but I would take this to mean that my creating and calling the <em>task_deid</em> from inside an actionPerformed method is okay to do.</p>
  
  <p>Now, these code pieces are nestled in an entire class called GUI that I have created with the Eclipse Window Builder tool.  The gist of the class is:</p>
  
  <pre><code>public class GUI {
  private JFrame frmToolWizard;
  private JPanel panel_Steps;
  ...
  private JPanel panel_runDeIDTool_23;
  
  ...
  private JButton btnStartDeidentification;
  private JProgressBar progressBar_deid;
  private JLabel lblProgress_deid;
  ...
  private DeIDTask task_deid;
  
  /**
   * Launch the application.
   */
  public static void main(String[] args) {
      EventQueue.invokeLater(new Runnable() {
          public void run() {
              try {
                  GUI window = new GUI();
                  window.frmToolWizard.setVisible(true);
              } catch (Exception e) {
                  e.printStackTrace();
              }
          }
      });
  }
  
  /**
   * Create the application.
   */
  public GUI() {
      initialize();
  }
  
  /**
   * Initialize the contents of the frame.
   */
  private void initialize() {
      frmToolWizard = new JFrame();
      ...
      panel_Steps = new JPanel();
      frmToolWizard.getContentPane().add(panel_Steps);
      ...
      panel_runDeIDTool_23 = new JPanel();
      panel_Steps.add(panel_runDeIDTool_23, "name_1406678727369229000");
      ...
      // Lot of other components here
      ...
      btnStartDeidentification = new JButton("Start De-Identification");
      ...
  }
  private class DeIDTask extends SwingWorker&lt;Void, Void&gt; {
  ...
  }
  </code></pre>
  
  <p>}   </p>
  
  <p>The whole point of calling the <em>done()</em> method is I want to finalize the progress bar, make it blank, and set my label under the progress bar to "Done." so the end user knows they can move on.  All of this that I want to do is very clearly seen in the DeIDTask <em>done()</em> method.</p>
  
  <p>Any help is greatly appreciated.  If this is an obvious answer I apologize in advance, because I am not seeing what I need to do to fix my problem.</p>