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
Did you read the API to find out other values for the setDefaultCloseOperation(...) method?
You can use:
DISPOSE_ON_CLOSE - the frame will close. If this is the last open frame for the application then the JVM will terminate as well
HIDE_ON_CLOSE - the frame is just set to invisible.
when user clicks the one that says new a new jframe from another class comes up with fields to enter information about a new dvd.
The real problem with your program is that you are using a frame as the popup window. You should be using a modal JDialog. An application should only ever have a single JFrame with multiple dialogs to gather additional information. A JDialog does not allow you to use EXIT_ON_CLOSE.
I had a similar problem and used jFrameInstanceVariable.setVisible(false);
as the action that occured when I hit my CANCEL button. But every time I clicked the button that popped up the JFrame afterward, all the old content was still there in addition to the new content created from pressing the button.
I fixed this by making a new instance of JFrame every time the button is pressed that pops up the JFrame.
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE)
If this is the case, make sure to use setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
on your JFrame when initializing, not setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
If your using a button like I think you said you were
this.dispose();
will do the trick..
I think you can also use DISPOSE_ON_CLOSE:
DISPOSE_ON_CLOSE (the default for JInternalFrame)
Hide and dispose of the window when the user closes it. This removes the window from the screen and frees up any resources used by it.