7

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?

sereda
  • 1,670
  • 11
  • 11

2 Answers2

5

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
  • 21,615
  • 7
  • 62
  • 83
-1

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

  • 3
    just to flag for future viewers of this thread: this method applies to the contents of the JFrame, not the JFrame itself in the context of the other windows on the system. – Dave Carpeneto Apr 05 '13 at 23:13