title: Why "javax.swing.JProgressBar" displays new values on top of old values when I update from another class?
body: <p>Problem:</p>
  
  <pre><code>ClassA
      static JProgressBar progressBar;
  ClassB
      ClassA.progressBar.setValue(0);
      ...
      ClassA.progressBar.setValue(10);
      ...
      ClassA.progressBar.setValue(20);
  </code></pre>
  
  <p>Progress bar displays 0, then 10 on top of the 0, then 20 on top of the 10.</p>
  
  <p>Code:</p>
  
  <pre><code>public class ClassA
  {
      static JProgressBar progressBar;
      public ClassA()
      {
          ...
          progressBar = new JProgressBar(0, 100);
          progressBar.setStringPainted(true);
          ...
      }
      public static void main(String[] args)
      {
          ClassA cA = new ClassA();
          cA.something();
      }
      public void something()
      {
          ...
          panel.add(progressBar, BorderLayout.CENTER);
          ...
      }
      ...
  }
  public class ClassB
  {
      public void something()
      {
          ...
          ClassA.progressBar.setValue(0);
          ClassA.progressBar.update(ClassA.progressBar.getGraphics());
          ...
      }
      ...
  }
  </code></pre>
  
  <p>I am also adding the progress bar to the panel. As it was mentioned above, it displays the progress bar and the percentage but it show each value on top of another.</p>
  
  <p><strong>EDIT:</strong>
  The problem is very similar to this: <a href="https://stackoverflow.com/questions/1097366/java-swing-revalidate-vs-repaint">Java Swing revalidate() vs repaint()</a>.
  However, instead of </p>
  
  <blockquote>
    <p>the old content is still actually visible (though obscured by the the
    new content)</p>
  </blockquote>
  
  <p>being problem with JPanel, mine is problem with JProgressBar.
  I tried <code>ClassA.progressBar.revalidate();</code> and <code>ClassA.progressBar.repaint();</code> but nothing works except <code>ClassA.progressBar.update(ClassA.progressBar.getGraphics());</code>, which, again, as it was mentioned above, displays new values on top of old values.</p>