This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

WindowListener not getting called.  RSS feed

 
Sundeep Gupta
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I created a JFrame and made the defaultCloseOperation to be 'DO_NOTHING', which as per doc says will call the WindowListener. But this is not happening.
Whatever value I set for defaultCloseOperation, windowListener is not getting called.
For DO_NOTHING -> Nothing happens
for DISPOSE_... -> window closes but application does not exit
for EXIT_ON_CLOSE -> application exits as set.



The functionality I have is

1. User presses the 'Save' button and a boolean is set to indicate that file is saved.
2. When user closes the window, that information (file being saved or not) need to be passed to the calling program
3. This application is invoked from Perl code, which has to do diff operations based on file's status (saved or not)

It could be fine we have other way to set the exit status, in which case I'll simply set default operation as EXIT_ON_CLOSE and then the Perl script should get different status

Please help

Thanks,
Sundeep
 
Rob Spoor
Sheriff
Posts: 21048
85
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because of the default close operation, the window is not being closed at all. It will print the "preparing to close" message, but then does nothing.

If you want to close the window when the X is pressed, dispose() the window in the windowClosing() method. This will then trigger the windowClosed() method.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!