tags:

views:

52

answers:

3
  • Java on Mac OS X

In a Swing GUI app I want to distinguish Application Quit from System Shutdown.

On Application Quit I want to show a confirmation dialog, but when the user chooses System Shutdown I simply want to quit the app since there was already a confirmation dialog from the system.

This might be of interest on other platforms too.

Dirk

+3  A: 

For application quit, add a listener and use windowClosed event on the main window.

For system quit, you can use addShutdownHook.

Valentin Rocher
A: 

Hi Dirk, welcome to Stack Overflow!

It's probably better in this case to stay with the standard behaviour. If you look at other Mac apps, like Terminal, TextEdit, etc., they all provide their own dialogs in all cases, whether on app quit, user logout, or system shutdown. Going with what users are used to is always the best choice!

Carl Norum
+1  A: 

The OSXAdapter sample application shows how to (transparently) handle certain Apple events like quitting via ⌘-Q or from the dock menu.

trashgod