Java: Preventing a child window’s close operation from exiting the app.Posted: February 16, 2007 | Author: tech0x20 | Filed under: Uncategorized | Leave a comment »
I included a second JFrame in NetBeans, which I used as a child window. When the child window was closed, all windows were closed. I finally figured out that the default close operation needed to be either HIDE_ON_CLOSE or DISPOSE_ON_CLOSE. The default in Java is HIDE_ON_CLOSE, but in NetBeans is EXIT_ON_CLOSE.
I first changed this property in the main window code that invokes the child window, but then I looked at the Properties page for the child window. “defaultCloseOperation” is the first property. “DISPOSE” can be selected here.
public void setDefaultCloseOperation(int operation)
- Sets the operation that will happen by default when the user initiates a “close” on this frame. You must specify one of the following choices:
WindowConstants): Don’t do anything; require the program to handle the operation in the
windowClosingmethod of a registered
WindowConstants): Automatically hide the frame after invoking any registered
WindowConstants): Automatically hide and dispose the frame after invoking any registered
JFrame): Exit the application using the
exitmethod. Use this only in applications.
The value is set to