Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Swing hack to query or set Z-order of a window?

Tags:

java

swing

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?

like image 352
sereda Avatar asked Apr 20 '09 09:04

sereda


People also ask

Is swing still used in Java?

JavaFX new fixes will continue to be supported on Java SE 8 through March 2022 and removed from Java SE 11. Swing and AWT will continue to be supported on Java SE 8 through at least March 2025, and on Java SE 11 (18.9 LTS) through at least September 2026.

What is a Swing application?

The Swing Application Framework (JSR 296) is a Java specification for a simple application framework for Swing applications, with a graphical user interface (GUI) in computer software. It defines infrastructure common to most desktop applications, making Swing applications easier to create.

What is Swing in Java?

Java Swing is a lightweight Java graphical user interface (GUI) widget toolkit that includes a rich set of widgets. It is part of the Java Foundation Classes (JFC) and includes several packages for developing rich desktop applications in Java.

What is Swing API?

Swing API is a set of extensible GUI Components to ease the developer's life to create JAVA based Front End/GUI Applications. It is build on top of AWT API and acts as a replacement of AWT API, since it has almost every control corresponding to AWT controls.


1 Answers

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...)

like image 173
Neil Coffey Avatar answered Oct 04 '22 04:10

Neil Coffey