Is there a swing hack to request or set the Z-order of a window?

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

Unfortunately, Swing does not seem to provide any way to find out or set the Z-order of the window (even relative to other windows in the same virtual machine).

We are dealing with setting the Z-order by calling toFront () in all windows in sequential order. But the Z-order request remains unresolved. (Adding focus listeners does not always work, for example, when you use the "Cascade" action of Windows in a group of windows.)

Any ideas?

+6
java swing
source share
2 answers

Not with any detail.

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

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

I believe that one of the reasons it was not a priority in Swing is that support for Z-ordering is completely platform dependent. (But hey, what not ...)

+5
source share

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

-one
source share

All Articles