Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Set z-order of Frames

843805Aug 31 2005 — edited Aug 31 2005
Hi, I have an application that has a lot of open Frames, and one main control bar frame. (Looks like an old Macintosh app, with windows all over the place.) When I'm using this app in windows, and switching back and forth between other apps, the windows associated with this app get "lost", ie hidden behind other frames.

What I'd like is when the user activates the control bar frame, it brings all other frames to front, followed by the control bar frame. So I wrote a window listener for the control bar Frame, see below. But it's not working, because apparently the windowActivated event sometimes happens after the bringFramesToFront method is called and sometimes not; when it does, the Frames fight each other for focus. The other problem is that, even when this works, the Frames come up in apparent random order. I'd like them to maintain thier z-order with respect to each other, but be on top of all my other windows.

Is there an easier way to get/set z-order for Frames in Java? Note, I am stuck using Frames and not JFrames because of legacy issues.

boolean ignore=false;
// I tried this with windowGainedFocus also, with the same result
public void windowActivated(WindowEvent e)
{
if (!ignore)
bringFramesToFront();
}

private void bringFramesToFront()
{
ignore = true;
Frame[] frames = Frame.getFrames();
for (int i = 0; i < frames.length; i++)
{
if (frames[i] != this)
frames.toFront();
}
toFront();
ignore = false;
// even though I called toFront() before setting ignore to false,
// sometimes a new windowGainedFocus event is received after
// this function exits.
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 28 2005
Added on Aug 31 2005
3 comments
484 views