I\'m creating a program to keep track of a list of DVD\'s. On the main page I have set up 2 JButtons. When the user clicks the one that says new, a new JFrame from another c
If you just hide the program, using HIDE_ON_CLOSE
or set.Visible(false)
, that is not a very good choice, because if you do something larger with more frames, the hidden frames will still be running, slowing down computer performance. The way, as other have said, is instead of using setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
, which will terminate the program when you click "X, closing all of the frames, use the following:
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
Try putting this.dispose();
inside the cancel button method.
To hide the window without it actually closing the program, do:
f.setVisible(false);