• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Catching the window cross button in JFrame

 
sandeep dhingra
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.
 
Nathan Pruett
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50171
79
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic