Adding JPanel onto another JPanel after button click

Posted by user1400650 on Stack Overflow See other posts from Stack Overflow or by user1400650
Published on 2012-09-19T09:06:49Z Indexed on 2012/09/19 9:38 UTC
Read the original article Hit count: 432

Filed under:
|
|
|
|

I'm using Netbeans IDE to make a gui application. I have a JFrame with a JPanel inside it. After a button click I want to display a different JPanel inside the first. The other JPanel is in a different file. How would I go about doing this? If this is not practical I don't mind replacing the first JPanel with the second one.

I've tried the following but it doesn't seem to work. I'm new to Java and Gui programming so I would appreciate any help I can get.

private void jButtonActionPerformed(java.awt.event.ActionEvent evt) {        
    JPanel2 jPanel2 = new JPanel2();
    JPanel1.add(jPanel2);
}

© Stack Overflow or respective owner

Related posts about java

Related posts about swing