wood burning stoves 2.0*
The moose likes Swing / AWT / SWT and the fly likes Catching the window cross button in JFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Catching the window cross button in JFrame" Watch "Catching the window cross button in JFrame" New topic

Catching the window cross button in JFrame

sandeep dhingra
Ranch Hand

Joined: Jul 30, 2005
Posts: 41
What I want to do is catch when the user presses the cross button to close the application which is on a JFrame. Or disable this buton when there is some processing going on in some dialog box, So that the program does not end with unexpected results.
Please if anybody knows.
Nathan Pruett

Joined: Oct 18, 2000
Posts: 4121

You'll have to add a WindowListener to your JFrame and code this in the windowClosing() method.

Write once, run anywhere, because there's nowhere to hide! - /. A.C.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 38045
. . . or to disable the "x for exit" button on the JFrame use a different Default Close Operation. See the JFrame API.
jQuery in Action, 2nd edition
subject: Catching the window cross button in JFrame
Similar Threads
JFrame confusion
Opening a frame from a dialog
How to make a JFrame Modal to another JFrame????[urgent....]
closing jframe with button question.
JFrame locks freezes