Difference between dispose and exit on close in java

If you have a few JFrames open and you close the one that is set to EXIT_ON_CLOSEthen all of the frames will be closed.

The opposite applies to the one with the DISPOSE_ON_CLOSE i.e. only it will be closed


DISPOSE_ON_CLOSE - Disposes the window when it's closed. You cannot redisplay the window, although the object window is still available in the memory


EXIT_ON_CLOSE will terminate the program.

DISPOSE_ON_CLOSE will call dispose() on the frame, which will make it disappear and remove the resources it is using. You cannot bring it back, unlike hiding it.

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

Tags:

Java