2

I'm using the GUI form designer from netBeans for the first time and I just can't change the content of my JFrame.

What I want is to include an other JPanel when I get into a menu of my menu bar, so I tried like I was used to do when I wasn't using the GUI form designer.

My code :

 private void menuItemAddAssistActionPerformed(java.awt.event.ActionEvent evt) {                                                  
    Container container = this.getContentPane();
    container.removeAll();
    container.add(new PanelAddAssist());
    container.repaint();
    this.setVisible(true);
}                                     

I've look up for something that could help me but I'm just lost with this generated code. :/

Thank's in advance.

MHogge
  • 5,408
  • 15
  • 61
  • 104

1 Answers1

1

What you want to do is use a CardLayout to switch between views, instead of trying to remove and add them. You can see How to Use CardLayout with NetBean GUI Builder for how to use it with the design tool. Also for the basics, see How to Use CardLayout Oracle tutorial

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720