title: Make an added JPanel visible inside a parent JPanel
body: <p>How to make an added <code>JPanel</code> visible inside a parent <code>JPanel</code>?</p>
  
  <p>I am using Netbeans for designing my UI.</p>
  
  <p>I have a <code>MainFrame.java</code>, which contains two panels; namely <code>headerPanel</code> and <code>bodyPanel</code>.</p>
  
  <p>In <code>headerPanel</code> I have put three buttons,let it be <code>button1</code>, <code>button2</code> and <code>button3</code>.</p>
  
  <p>Also I have created three separate files extending <code>JPanel</code>, name it <code>panel1</code>, <code>panel2</code> and <code>panel3</code>.</p>
  
  <p>Then I added all my three panels inside <code>bodypanel</code> in <code>MainFrame.java</code> in constructor.</p>
  
  <pre><code>bodyPanel.add(panel1);
  bodyPanel.add(panel2);
  bodyPanel.add(panel3);
  </code></pre>
  
  <p>I want that on clicking the respective buttons only respective panels should appear in the <code>bodypanel</code> in mainframe, i.e. if I click <code>button1</code> then <code>panel1</code> should be displayed.</p>
  
  <p>I have already tried the following code in <code>button1</code> mouse listener method:</p>
  
  <pre><code>bodyPanel.validate();
  bodyPanel.getComponent(0).setVisible(true);
  </code></pre>
  
  <p>But <code>panel1</code> does not appear. I did it cause added components in a panel are allotted index. So first I tried to get the components and then make it visible. It did not work.</p>