Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: User Interface Design
Expertise: Beginner
Apr 5, 1999



Building the Right Environment to Support AI, Machine Learning and Deep Learning

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 a JFrame is to call its setDefaultCloseOperation(). This method 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 the WindowConstants interface, so it is also possible to use JFrame.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.

DevX Pro
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date