title: JFrame getContentPane.removeAll() only working between a .setVisible(false) and .setVisible(true)
body: <p>The folloing code is supposed to reset the frame gameFrame:</p>
  
  <pre><code>private void reset()
  {
      moveCount = 0;
      gameFrame.setVisible(false);
  
      gameFrame.getContentPane().removeAll();
      gameFrame.getContentPane().revalidate();
      gameFrame.getContentPane().repaint();
  
      board.newBoard();
      createGameUI(board.getWidth(),board.getHeight());
  
      gameFrame.setVisible(true);
  
  }
  </code></pre>
  
  <p>However it only works by first setting visibility of gameFrame to false, removing all components, adding a fresh set of components, and then setting the gameFrame to visible.</p>
  
  <p>What is the proper way to do this?</p>
  
  <p>Thanks,</p>
  
  <p>Oli</p>
  
  <p>EDIT:</p>
  
  <p>I've tried doing:</p>
  
  <pre><code>private void reset()
  {
      moveCount = 0;
  
      //gameFrame.setVisible(false);
      gameFrame.getContentPane().removeAll();
  
      createGameUI(board.getWidth(),board.getHeight());
  
      gameFrame.getContentPane().revalidate();
      gameFrame.getContentPane().repaint();
      //gameFrame.setVisible(true);
  
  }
  </code></pre>
  
  <p>However this now just freezes the program when I press the reset button.</p>