I have a Swing application which consists of a single JFrame set to Always On Top.
When running under Windows, I use the following code to open the the native default email client and browser respectively:
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + Utils.formatMailtoUrl(to, subject, body));
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
Because the JFrame is set to Always On Top while the typical default browser or email client(IE and Outlook for our customer) does not open as Always On Top, the former obstructs the later.
Our current "solution" is to minimize the JFrame at the same time the native windows are opened. But this turns out to be a 508 compliance issue, and we are being asked to:
- Not minimize the JFrame.
- Return focus to the JFrame after either the browser or email client are closed
The strategy I have in mind is to "turn off" the Always On Top state of the JFrame and have some kind of callback or event listener which will notify the JFrame that email or browser windows have been closed and then switch the JFrame back to the Always On Top state and set focus.
Because this is a Java app, I am worried this is next to impossible because we are talking about native interop. Is my strategy doable, is there a better doable strategy, and, most importantly, how can it be done?!
Thanks in advance!
[Edit]
I am having some success with the following:
- When the action for opening the browser (for example) is fired, turn off the JFrame Always On Top setting.
- Have a on window focus action which turns on the JFrame Always On Top setting.
- If the user does not navigate to any other windows besides the browser, then when the browser closes the JFrame will automatically regain focus and thus be set back to Always On Top
There are two drawbacks I see with this approach. The first is that the user might manually go back to the JFrame window before closing the browser window causing the JFrame to regain focus and get stuck in Always On Top mode. But this might be acceptable. The second issue is that the JAWS version 9 screen reader goes crazy and re-reads the last focused component at least 3 times once the JFrame regains focus.