tags:

views:

318

answers:

2

We are trying to save the state of the application on exit and restore it on startup. Part of the state is the relative Z-order of all JFrames.

Unfortunately, Swing doesn't seem to provide any method to learn or set Z-order of a Window (even relative to other windows in the same VM).

We deal with setting the Z-order by calling toFront() on all windows in successive order. But querying Z-order remains unsolved. (Adding focus listeners doesn't work always, for example, when one uses Windows' "Cascade" action on a group of windows.)

Any ideas?

+1  A: 

Not with any granularity.

As you say, you can call toFront() and toBack(), and you can ask a window to "stay on top", but that's pretty much it.

Another option is to have a frame with internal frames, and use setComponentZOrder() (this only works for internal components though-- you have to call it on the container).

I believe one of the reasons for it not having been a priority in Swing is that support for Z-ordering is quite platform-dependent. (But hey, what isn't...)

Neil Coffey
A: 

You can use setComponentZOrder(Component c, int layer) and getComponentZOrder(Component c) from the Container class. There is a JDC Tech Tips on this: http://72.5.124.55/developer/JDCTechTips/2005/tt0118.html