如何获得所有顶级窗口javafx?

我在AWT中看到了一个方法: java.awt.Window.getWindows() 。 在JavaFx中,有没有任何方法可以获得所有窗口的JavaFx应用程序?

谢谢,

AFAIK,仍然没有正确的方法来做到这一点。

虽然有一种肮脏的短期方式:

浏览javafx.stage.Window的源代码 ,有一个静态方法似乎javafx.stage.Window#impl_getWindows()你的期望: javafx.stage.Window#impl_getWindows()

但是有一些免责声明:

 /** * 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 impl_getWindows() { final Iterator iterator = AccessController.doPrivileged( new PrivilegedAction() { @Override public Iterator run() { return windowQueue.iterator(); } } ); return iterator; } 

对于运行java8的javafx8使用

 FXRobotHelper.getStages() or StageHelper.getStages() 

这将检索所有Stages本质上是一个Window本身(它扩展了Window类)

最终在Java 9中已经正确修复了这个问题。请参阅javafx.stage.Window.getWindows()

返回一个列表,其中包含对当前显示的JavaFX窗口的引用。 该列表是不可修改的 – 尝试修改此列表将导致在运行时抛出UnsupportedOperationException。

这在Java 9中是必不可少的,因为其他涉及StageHelperFXRobotHelper解决方案不再可能,因为这些解决方案存在于com.sun.javafx包中,无法再访问它。