title: Converting JFrame to JPanel
body: <p>I currently have written some Java Swing using a <code>JFrame</code> and it works fine. </p>
  
  <p>But now I need to use multiple screens and they are done using <code>cardlayouts</code>. </p>
  
  <p>So i need to convert my <code>JFrame</code> to <code>JPanel</code>. Currently I have this line for my <code>JFrame</code></p>
  
  <pre><code>mainFrame.getContentPane().add(c4Panel,BorderLayout.CENTER); 
  </code></pre>
  
  <p>But if I convert <code>mainFrame</code> to <code>JPanel</code> I cant use <code>getContentPane()</code> IDE tells me to use <code>getRootPane()</code></p>
  
  <p>but I get error on this line</p>
  
  <pre><code>mainPanel.getRootPane().add(c4Panel,BorderLayout.CENTER); 
  </code></pre>
  
  <p>The error I get is </p>
  
  <pre><code>Exception in thread "main" java.lang.NullPointerException
  </code></pre>