title: Erase Swing Content Pane/Panel & display a new panel
body: <p>I have created an applet where when you press the button "Forgot Pass" I erase the current JPanel on the applet &amp; create a new JPanel that displays the JComponents related to Retrieving/Forgetting a password.</p>
  
  <p><em>I can successfully clear the JPanel using .removeAll(); <strong>BUT</strong> after I create all my new JComponents &amp; add them to the content pane (main JPanel) the applet just goes gray &amp; doesn't show the new JPanel &amp; components <strong>UNLESS</strong> I resize the applet, then it repaints &amp; works.</em></p>
  
  <p>I have tried putting .invalidate() after I have created all the new JComponents but that still doesn't refresh the applet?</p>
  
  <p><strong>How can I make my JPanel appear after I clear it with .removeAll() &amp; add different JComponents to it?</strong></p>
  
  <p>Code:  </p>
  
  <pre><code>public class App extends JApplet
  {
      JPanel mainPanel; 
  
      public void init()
      {
          SwingUtilities.invokeAndWait( new Runnable() {
              public void run()
              {
                  showLoginPanel(); // this shows fine on loading
              }
          });
  
      }
  
      public void showForgotPassPanel()
      {
          mainPanel.removeAll();
  
          mainPanel = (JPanel) getContentPane();
          Box hBox  = Box.createHorizontalBox();
          Box vBox  = Box.createVerticalBox();
          mainPanel.setLayout( new BorderLayout() ); 
  
          ... create components
  
          ... add components to mainPanel
  
          mainPanel.invalidate(); // doesn't make new layout visible, not unless I resize the applet
      }
  }
  </code></pre>