Search code examples
javaswingjframejbutton

How to open new JFrame when clicking JButton?


I have a simple problem with opening a new JFrame called focalSumFrame while clicking on JButton called focalSum. I am working in netBeans IDE. My code looks like this:

private void focalSumActionPerformed(java.awt.event.ActionEvent evt) {                                         
    focalSumFrame.pack();
    focalSumFrame.setVisible(true);   
}

Solution

  • It's more efficent and easier to use JDialogs and/or CardLayout for alternative pages of your program. Creating other JFrames to use as your pop-ups is a very ineffective way to go about what you're trying to do.

    JDialog Information

    Card Layout Information