In my Swing application, I’m using a custom module to record a screen cast.
However, I’m a bit hung up on when to force the recording to stop. Right now, I check to see if the user still wishes to record (meaning that they haven’t clicked the ‘stop’ button) and if the application is still open (closing the application causes the recording to stop gracefully).
The problem is that the recording will continue if the application gets pushed behind other apps or minimized, causing recording of ‘junk’. I need the recording to stop when the application is no longer ‘on top’ of the screen. Using the application’s focus doesn’t seem to work due to other dialogs and things popping up.
Suggestions?
You may want to try adding a WindowListener and override the windowDeactivated() event, which should get called when the frame is no longer the “active window” according to the operating system.
UPDATE:
If you are conscientious about making sure that your child dialogs and windows are owned by your application (making sure you pass in your application frame as the owner), then you could make your WindowListener do something like this:
Then you will be able to determine if the window focus has left your application altogether or if the focus has just changed to a different child window/dialog.