title: Basic Indeterminate JProgress Bar Usage
body: <p>I simply want to have an indeterminate JProgressBar animate in the bottom left corner of my frame when a long download is being done.</p>
  
  <p>I've looked through many tutorials, none of which are clear to me. I simply want to have it animate while the file is being downloaded in the background. Each way I've tried this, it doesn't animate the progress bar until <em>after</em> the download is done.</p>
  
  <p>I need help knowing where to place my download() call.</p>
  
  <pre><code>class MyFunClass extends JFrame {
    JProgressBar progressBar = new JProgressBar();
  
    public void buttonClicked() {
      progressBar.setVisible(true);
      progressBar.setIndeterminate(true);
  
      SwingUtilities.invokeLater(new Runnable() {
        public void run() {
          progressBar.setIndeterminate(true);
          progressBar.setVisible(true);
  
          // Do I do my download() in here??
  
      }});
  
      // Do download() here???
      progressBar.setVisible(false);
    }
  }
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <hr>
  
  <p><br /></p>
  
  <h1>Solution</h1>
  
  <p><em>Edit:</em> For those who have a similar issue to me in the future, this is the basic solution for a basic problem. This isn't my code verbatim, but a general sketch. Inside <code>buttonClicked()</code>:</p>
  
  <pre><code>public void buttonClicked() {
    class MyWorker extends SwingWorker(String, Object) {
       protected String doInBackground() {
         progressBar.setVisible(true);
         progressBar.setIndeterminate(true);
  
         // Do my downloading code
         return "Done."
       }
  
       protected void done() {
          progressBar.setVisible(false)
       }
    }
  
    new MyWorker().execute();
  
  }
  </code></pre>