JFrame Exit on close Java

You need the line


Because the default behaviour for the JFrame when you press the X button is the equivalent to


So almost all the times you’ll need to add that line manually when creating your JFrame

I am currently referring to constants in WindowConstants like WindowConstants.EXIT_ON_CLOSE instead of the same constants declared directly in JFrame as the prior reflect better the intent.

Leave a Comment