title: JButton stays in pressed state
body: <p>In my Java GUI app I have a <code>JButton</code> and when clicked it calls a <code>function</code> to connect to a <code>database</code>, then calls a <code>function</code> to <code>clear</code> a <code>table</code> in the <code>DB</code>, then calls a <code>function</code> that reads text from one file and loads <code>variables</code>, which calls a <code>function</code> that reads text from another file, compares the <code>data</code> from both and then calls a <code>function</code> to either <code>update</code> or <code>insert</code> data in the DB, all of that works fine. </p>
  
  <p>However my question is related to the <code>JButton</code>, when its clicked I want to run a <code>Indeterminate progress bar</code> just so the user knows work is being done and then right before it leaves the the <code>action listener setIndeterminate to false</code> and set the value of the <code>progress bar</code> to <code>100(complete)</code>, but in my case when you click the <code>button</code> it stays in the clicked state and the <code>progress bar</code> freezes.</p>
  
  <p>What should I implement to prevent this? threading possibly? but Im quite new to threading in java. here is my action listener: </p>
  
  <pre><code>    private class buttonListener implements ActionListener
          {
              public void actionPerformed(ActionEvent e)
              {
                  if( e.getSource() == genButton )
                  {
                      progressBar.setIndeterminate(true);
                      progressBar.setString(null);
                      try 
                      {
                          dbConnect(); //connects to DB
                          clearSchedules(); // deletes data in tables
                          readFile(); // reads first file and calls the other functions
                          dbClose();// closes the DB
                          progressBar.setIndeterminate(false);
                          progressBar.setValue(100);
                      } 
                      catch (Exception e1){
                          System.err.println("Error: " + e1.getMessage());
                      }
                  }
              }
          }
  </code></pre>
  
  <p>On a side note, I would like to have the action bar actually move as the the program progresses but I wasnt sure how to monitor its progress.</p>
  
  <p>Thanks, Beef.</p>
  
  <p><strong>UPDATE</strong>  here is my example of SwingWorker and how I used it:</p>
  
  <p>Declared globally</p>
  
  <pre><code> private functionWorker task;
  
  
      private abstract class functionWorker extends SwingWorker { 
  
          public void execute() {
              try {
                  dbConnect();
              } catch (SQLException e) {
                  e.printStackTrace();
              }
              clearSchedules();
              try {
                  readFile();
              } catch (IOException e) {
                  e.printStackTrace();
              }
              dbClose();
          }
      }
  </code></pre>
  
  <p>Inside my actionPerformed method</p>
  
  <pre><code>if( e.getSource() == genButton )
              {
  
                  progressBar.setIndeterminate(true);
                  progressBar.setString(null);
                  try 
                  {
                      task.execute();
  
                      progressBar.setIndeterminate(false);
                      progressBar.setValue(100);
                  } 
                  catch (Exception e1){
                      System.err.println("Error: " + e1.getMessage());
                  }
              }
  </code></pre>