12

I have a single frame created using Netbeans GUI builder when I view the frame properties one of the first options is default close operation the options listed are: DISPOSE_ON_CLOSE, HIDE_ON_CLOSE, DO_NOTHING_ON_CLOSE & EXIT_ON_CLOSE I understand the middle two but, whats the difference between DISPOSE_ON_CLOSE and EXIT_ON_CLOSE ? I have tried testing both but to me they do the same thing to me

Lukas Rotter
  • 4,158
  • 1
  • 15
  • 35
Ayvadia
  • 339
  • 1
  • 4
  • 19

3 Answers3

15

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()

Community
  • 1
  • 1
Garrett Hall
  • 29,524
  • 10
  • 61
  • 76
9

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

Dhanuka
  • 2,826
  • 5
  • 27
  • 38
Katana24
  • 8,706
  • 19
  • 76
  • 118
2

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

  • 1
    "although the object window is still available in the memory".=> it still *uses* memory (until it is garbage collected). Saying it is "available" is confusing at least. And yet another thing: you *can* redisplay the window, though it will require recreating it (using the `new` keyword). – Alain BECKER Mar 31 '21 at 16:39