I'm using netbeans IDE and I created a Jframe with two Jpanels one is for Jbuttons and other one is for load another Jpanels to it when clicks those buttons. I tried to do it from buttonclick action.

Jpanel2 j2=new Jpanel2(); 
JPanel1.add(j2); 
j2.setVisible(True);

but this code is not working. I want to know how can I do this. (I think this is also same as loading JinternelFrames)