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.

[1061 byte] By [therevolutiona] at [2007-11-26 14:30:24]
# 1
setAlwaysOnTop is a feature of the OS so you can't change it.The best solution would be using JDialog instead of JFrame for the other frames.
Rodney_McKaya at 2007-7-8 2:25:09 > top of Java-index,Desktop,Core GUI APIs...
# 2
I know I can't change setAlwaysOnTop behavior. I just wondered if anyone out there knows of a way to replicate that functionality but keep it limited to my app. I don't want to cover other application windows.I can't use JDialogs, for various reasons. I have to stick with
therevolutiona at 2007-7-8 2:25:09 > top of Java-index,Desktop,Core GUI APIs...
# 3
You will have to decide what is closer to what you need JDialog or setAlwaysOnTop, because those are the only options available.Why can't you use JDialog?
Rodney_McKaya at 2007-7-8 2:25:09 > top of Java-index,Desktop,Core GUI APIs...
# 4
I need the ability to hide the original frame and leave the created frames visible. Can't do that with dialogs.
therevolutiona at 2007-7-8 2:25:09 > top of Java-index,Desktop,Core GUI APIs...
# 5
This is not completely true.You can set the size of the JFrame to 0,0 and setLocation -50,-50.But the JDialog will remain visible.
Rodney_McKaya at 2007-7-8 2:25:09 > top of Java-index,Desktop,Core GUI APIs...
# 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?

therevolutiona at 2007-7-8 2:25:09 > top of Java-index,Desktop,Core GUI APIs...
# 7
There is only one thing I can think of:Playing with the alwaysOnTop flag when your frames gain and loses focus.Build a global focus manager and when the focus is lost by all frames set the alwaysOnTop flag to false and vice versa.But I'm not sure it will work
Rodney_McKaya at 2007-7-8 2:25:09 > top of Java-index,Desktop,Core GUI APIs...
# 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?

therevolutiona at 2007-7-8 2:25:09 > top of Java-index,Desktop,Core GUI APIs...
# 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.

reportjeffa at 2007-7-8 2:25:09 > top of Java-index,Desktop,Core GUI APIs...