是否有 Swing hack 来查询或设置窗口的 Z 顺序? [英] Is there a Swing hack to query or set Z-order of a window?

查看:20
本文介绍了是否有 Swing hack 来查询或设置窗口的 Z 顺序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们试图在退出时保存应用程序的状态并在启动时恢复它.状态的一部分是所有 JFrame 的相对 Z 顺序.

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.

不幸的是,Swing 似乎没有提供任何方法来学习或设置窗口的 Z 顺序(甚至相对于同一 VM 中的其他窗口).

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

我们通过在所有窗口上依次调用 toFront() 来处理设置 Z 顺序.但是查询 Z 顺序仍未解决.(添加焦点侦听器并不总是有效,例如,当一个人在一组窗口上使用 Windows 的级联"操作时.)

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

有什么想法吗?

推荐答案

没有任何粒度.

如您所说,您可以调用 toFront() 和 toBack(),并且您可以要求一个窗口保持在顶部",但仅此而已.

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.

另一种选择是使用带有内部框架的框架,并使用 setComponentZOrder()(不过这仅适用于内部组件——您必须在容器上调用它).

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

我认为它在 Swing 中没有成为优先事项的原因之一是对 Z 排序的支持非常依赖于平台.(但是嘿,什么不是...)

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

这篇关于是否有 Swing hack 来查询或设置窗口的 Z 顺序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆