title: Java Swing revalidate() vs repaint()
body: <p>I'm putting together a Swing application where I often want to replace the contents of a JPanel. To do this, I'm calling <code>removeAll()</code>, then adding my new content, then calling <code>revalidate()</code>.</p>
  
  <p>However I'm finding that the old content is still actually visible (though obscured by the the new content). If I add a call to <code>repaint()</code> in addition to <code>revalidate()</code>, it works as expected.</p>
  
  <p>I'm sure on other occasions I've experienced that just calling <code>revalidate()</code> is enough.</p>
  
  <p>So basically my question is - should I need to call both functions and if not, when should I call each of them?</p>