This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
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 The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript 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
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: 38449
    
  23
. . . or to disable the "x for exit" button on the JFrame use a different Default Close Operation. See the JFrame API.
 
 
subject: Catching the window cross button in JFrame