title: JProgressBar.setMaximum(int) sometimes doesn't seems to work
body: <p>I have a JProgressBar that I need to set a new <code>minimum</code>, <code>maximum</code> and <code>progress</code> value each time a task of a queue is done, using the code below:</p>
  
  <pre><code>this.progressBar.setMinimum(minimum);
  this.progressBar.setMaximum(maximum);
  this.progressBar.setValue(progress);
  </code></pre>
  
  <p>But, I noticed that sometimes, the <code>setMaximum(int)</code> method doesn't seems to work, because the progress bar still working with the old maximum value.</p>
  
  <p>Then I wrote some test code and ran it:</p>
  
  <pre><code>progressBar.setMaximum(10);
  System.out.println(progressBar.getMaximum());
  </code></pre>
  
  <p>Sometimes it prints <code>10</code> as expected, and sometimes prints the old value: anything different from 10.</p>
  
  <p>I spent hours on Google and javadocs, tried to call <code>revalidate()</code> and <code>repaint()</code> on JProgressBar's parent, and nothing. I also tried to call <code>Thread.sleep(10)</code> to wait AWT threads to run another tasks and didn't work.</p>
  
  <p>Any ideas?</p>
  
  <p><strong>EDIT:</strong> Provided some more code:</p>
  
  <pre><code>/* Applet that construct the view and init a Thread. */
  public class FastApplet extends Applet {
      private JProgressBar progressBar;
      private JPanel panel;
      private Runnable runnable;
  
      @Override
      public void init() {
          try {
              java.awt.EventQueue.invokeAndWait(new Runnable() {
                  @Override
                  public void run() {
                      createAndShowGUI();
                      initThreads();
                  }
              }
          } catch (Exception e) {
              e.printStackTrace();
          }
      }
  
      private void createAndShowGUI() {
          panel = new JPanel();
          progressBar = new JProgressBar();
          progressBar.setStringPainted(true);
          panel.add(progressBar);
      }
  
      private void initThreads() {        
          runnable = new MyRunnable(progressBar);     
          Thread thread = new Thread(runnable);
          thread.start();
      }
  }
  
  /* Runnable that update progress and call setMaximum(int) on JProgressBar */
  public class MyRunnable {
      private int progress;
      private final JProgressBar progressBar;
  
      MyRunnable(JProgressBar progressBar) {
          this.progressBar = progressBar;
      }
  
      @Override
      public void run() {
          // do the tasks and update the progressBar using progressBar.setValue(progress)
          // when done, reset the progress bar with the a new maximum:
          defineNewProgressBar(0, 0, newMaximum);
      }
  
      public void defineNewProgressBar(int progress, int minimum, int maximum) {
          this.progress = progress;
  
          Component component = progressBar.getParent();
          JPanel panel = (JPanel) component;
  
          this.progressBar.setMinimum(minimum);
          this.progressBar.setMaximum(maximum);
          this.progressBar.setValue(progress);
  
          panel.revalidate();
          panel.repaint();
      }
  }
  </code></pre>