aspose file tools*
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
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
Author

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
Bartender

Joined: Oct 18, 2000
Posts: 4121

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


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

Joined: Oct 13, 2005
Posts: 39885
    
  28
. . . or to disable the "x for exit" button on the JFrame use a different Default Close Operation. See the JFrame API.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Catching the window cross button in JFrame