JFrame Exit Button

JFrame Exit Button

Is it possible to remove the close button from a JFrame or at least disable it?

It is possible to disable the function of the close button on a JFrame, but it does not appear to be possile to remove it. The close button is placed by the native windowing system, and there do not seem to be any API hooks provided to tell the windowing system not to draw the button.

The easiest way to disable the close action on aJFrame is to call its setDefaultCloseOperation(). Thismethod accepts an integer as a parameter representing the operation to perform. This value must be one of the constants defined in the WindowConstants interface. Using the value WindowConstans.DO_NOTHING_ON_CLOSE will do the trick. You will notice that JFrame implements theWindowConstants interface, so it is also possible to useJFrame.DO_NOTHING_ON_CLOSE, which may be clearer. Note, however, that JInternalFrame provides the ability to control the presence or absence of an exit button.


Share the Post: