This is what I put as a menu option, where I made a button on a JFrame to display another JFrame . I wanted only the new frame to be visible, and not to destroy the one behind it. At first I hid the first JFrame , and the new one became visible. After closing the new JFrame I deleted it and then repeated the old one.
Note. The following code extends Ravinda's answer, and ng 's JButton :
ng.addActionListener((ActionEvent e) -> { setVisible(false); JFrame j = new JFrame("NAME"); j.setVisible(true); j.addWindowListener(new java.awt.event.WindowAdapter() { @Override public void windowClosing(java.awt.event.WindowEvent windowEvent) { setVisible(true); } }); });
Cody Nov 20 '17 at 21:20 2017-11-20 21:20
source share