Difference between delete and exit on close in java

I have a single frame created using the NetBeans GUI Builder when I view the properties of a frame. One of the first options is the default close operation, the parameters listed are: DISPOSE_ON_CLOSE , HIDE_ON_CLOSE , DO_NOTHING_ON_CLOSE and EXIT_ON_CLOSE I understand the second, but what is the difference between DISPOSE_ON_CLOSE and EXIT_ON_CLOSE ? I tried to test both, but for me they do the same with me.

+7
java
source share
3 answers

EXIT_ON_CLOSE terminates the program.

DISPOSE_ON_CLOSE will call dispose() on the frame, which will cause it to disappear and remove the resources it uses. You cannot return it, unlike hiding it.

See aslo JFrame.dispose () vs System.exit ()

+9
source share

If you have multiple JFrames open and close the one set to EXIT_ON_CLOSE , then all frames will be closed.

The opposite is true with DISPOSE_ON_CLOSE ie only it will be closed

+6
source share

EXIT_ON_CLOSE terminates the program. Unlike the default, HIDE_ON_CLOSE, which simply hides the program, but continues to run in the background. DISPOSE_ON_CLOSE will recycle the program means that it will delete all program resources i.e.
If you have multiple JFrames open and close the one that has EXIT_ON_CLOSE, it will close all JFrames and exit the application.

If you close the one that DISPOSE_ON_CLOSE will only have that one JFrame will be closed.

0
source share

All Articles