Window.setAlwaysOnTop() functionality without hiding other apps?
Hi all,
My app starts out with one JFrame, and the user has the ability to create more JFrames. I'd like for those user-created JFrames to always stay on top of the original JFrame.
Now, I know I can call setAlwaysOnTop(true) on the spawned JFrames, but I don't want them to stay on top of other applications too - just on top of my original frame. Otherwise, using setAlwaysOnTop meets my needs exactly.
Trying to enforce the z-order manually doesn't work quite right, either. I can call toFront() in order from back to front when I lose/gain focus in any frame, at which point it looks fine, but if the original frame has the focus, clicking inside the frame again causes it to come to the front without any focus events being thrown. I need focus to remain in the original frame without the frame coming to the front.
As I said before, the behavior when using setAlwaysOnTop(true) in the spawned frames works great, but I just don't want those frames sitting on top of other apps as well. Any ideas or suggestions? Thanks.
# 6
Yes, I know about that. I tried it long ago, and I remember something still wasn't working quite right. This was about a year ago. Anyway, I can't move to dialogs. As I mentioned before, there are other reasons as well. I need unique entries in the Windows taskbar, for one. There's another reason I'm forgetting... but anyway, can we move off the topic of dialogs? Any other ideas?
# 8
I thought of the same thing this morning. :) However, it doesn't work. When a frame loses focus and/or is deactivated (I tried both), the call to frame.setAlwaysOnTop(false) doesn't always get applied before the OS transfers focus to the other application. Sometimes it will, sometimes it won't.
It was a good idea, though. :) Ideas like this one are what I was hoping to get out of this thread. Thanks for your suggestions so far, Rodney.
Any other ideas?
# 9
I tried to add a "Hide on Deactivate" feature to my floating palettes/inspectors. I did this with a AWTEventListener.eventDispatched() method that set's my setAlwaysOnTop windows to not visible when there is a WINDOW_DEACTIVATED with no corresponding opposing WINDOW_ACTIVATED. Then it sets all setAlwaysOnTop windows visible on any WINDOW_ACTIVATED.
This works most of the time, but under some weird circumstances, my app still has active windows even when deactivated, so this solution is buggy. I was hoping to find a real way to detect when a Swing application is deactivated, but so far I haven't found this functionality anywhere.