[英]How to get all top level window javafx?
I saw a method in AWT: java.awt.Window.getWindows()
. 我在AWT中看到了一个方法:
java.awt.Window.getWindows()
。 In JavaFx, is there any method to get all window JavaFx application? 在JavaFx中,是否有任何方法可以获取所有窗口的JavaFx应用程序?
Thanks, 谢谢,
for javafx8 running java8 use 对于运行java8的javafx8使用
FXRobotHelper.getStages()
or
StageHelper.getStages()
This will retrieve all Stages which is essentially a Window itself ( it extends Window class) 这将检索本质上是Window本身的所有Stage(它扩展了Window类)
AFAIK, there is still no proper way to do this. AFAIK,仍然没有适当的方法来执行此操作。
Although there is a dirty and short term way : 尽管有一种肮脏的短期方法:
Browsing the source code of javafx.stage.Window
, there is a static method which seems to do what you are expecting : javafx.stage.Window#impl_getWindows()
. 浏览
javafx.stage.Window
的源代码 ,有一种静态方法似乎javafx.stage.Window#impl_getWindows()
您的期望: javafx.stage.Window#impl_getWindows()
。
But there is a bunch of disclaimers : 但是有很多免责声明:
/**
* Return all Windows
*
* @return Iterator of all Windows
* @treatAsPrivate implementation detail
* @deprecated This is an internal API that is not intended for use and will be removed in the next version
*/
@Deprecated
@NoInit
public static Iterator<Window> impl_getWindows() {
final Iterator iterator = AccessController.doPrivileged(
new PrivilegedAction<Iterator>() {
@Override public Iterator run() {
return windowQueue.iterator();
}
}
);
return iterator;
}
This has finally been fixed properly in Java 9. See javafx.stage.Window.getWindows() 终于在Java 9中正确修复了该错误。请参见javafx.stage.Window.getWindows()
Returns a list containing a reference to the currently showing JavaFX windows.
返回一个列表,其中包含对当前显示的JavaFX窗口的引用。 The list is unmodifiable - attempting to modify this list will result in an UnsupportedOperationException being thrown at runtime.
该列表不可修改-尝试修改此列表将导致在运行时引发UnsupportedOperationException。
This is essential in Java 9 as the other solutions involving StageHelper
or FXRobotHelper
are no longer possible as these exist in com.sun.javafx
package which can no longer be accessed. 这在Java 9中至关重要,因为不再有涉及
StageHelper
或FXRobotHelper
的其他解决方案,因为这些解决方案存在于com.sun.javafx
程序包中,无法再访问。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.