title: repaint in a loop
body: <p>I am writing a game using Java Swing. I want to paint each time a loop executes with a small delay in between to create a cascade effect on screen. I believe that the efficiency routines in the system are collapsing the calls to <code>repaint()</code> into a single call. At any rate, the changes all occur at once after the total delay. Is there some way to force the system to repaint immediately and then delay on each iteration of the loop? </p>
  
  <p>My Code:</p>
  
  <pre><code>for(int i=0;i&lt;10;i++){
      JButton[i].setBackground(Color.WHITE);
      JButton[i].repaint();
      Thread.sleep(2000);
      JButton[i].setBackground(Color.GRAY);
      JButton[i].repaint();
  }
  </code></pre>