• Post Reply Bookmark Topic Watch Topic
  • New Topic

Catching the window cross button in JFrame  RSS feed

 
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'll have to add a WindowListener to your JFrame and code this in the windowClosing() method.
 
Marshal
Posts: 59074
180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . or to disable the "x for exit" button on the JFrame use a different Default Close Operation. See the JFrame API.
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!