Well behaved windows programs need to allow users to save their work when they are shutting the PC down.
How can I make my app detect the shutdown event? Any solution should allow the user to abort the shutdown if user selects, say "Cancel".
The normal Swing window closing hook doesn't work, nor does adding a shutdown hook.
On testing, the methods of WindowListener (windowClosing,windowClosed, etc) do not get called.
The answer I have accepted requires the use of platform specific code (JNI to register for WM_QUERYENDSESSION ). Isn't this a bug on Swing?
See http://forums.sun.com/thread.jspa?threadID=481807&messageID=2246870