title: How to add components to JFrame once it's visible without having to resize it?
body: <p>I have a program where I have a <code>JFrame</code> with a <code>JButton</code> in it. When the user clicks the <code>JButton</code>, all <code>Components</code> of the <code>JFrame</code> are removed, and a <code>JPanel</code> with red background is added to it.</p>
  
  <p>When I click the <code>JButton</code>, that red <code>JPanel</code> does not become visible unless I resize the <code>JFrame</code> (I am using Windows 7). Is there a way to achieve what I want without having to manually resize the <code>JFrame</code>?</p>
  
  <p>Here is a part of the code I am using:</p>
  
  <pre><code>public class Demo implements ActionListener{
      public static void main(String args[]){
             ...............
          button.addActionListener(this); //'button' is an object of Jbutton class.
          frame.setVisible(true); //'frame' is an object of JFrame class.
          ............
      }
  
      public void actionPerformed(ActionEvent ae){
          frame.removeAllComponents();
          frame.add(panel1); //panel1 is an object of Jpanel class with red  background.
  
          /* Here is where my problem lies.
             panel1 is not visible to me unless I manually resize the JFrame. */
      }
  }
  </code></pre>