And by JDesktopPane, I'm sure you mean JInternalFrame
See what methods the latter has? Most notably one that starts with "add" and ends with "Listener"? It's the clos
ing event that will be triggered just before it is actually closed. Don't forget to set the right default close operation (hint hint hint); the default is no longer the one you want.