如何获得所有顶级窗口javafx



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

谢谢,

为javafx8运行java8使用

FXRobotHelper.getStages()
 or 
StageHelper.getStages()

这将检索所有的阶段,这实际上是一个窗口本身(它扩展了窗口类)

我敢说,目前还没有合适的方法来做到这一点。

虽然有肮脏和短期方式:

浏览javafx.stage.Window的源代码,有一个静态方法似乎做你所期望的: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<Window> impl_getWindows() {
    final Iterator iterator = AccessController.doPrivileged(
        new PrivilegedAction<Iterator>() {
            @Override public Iterator run() {
                return windowQueue.iterator();
            }
        }
    );
    return iterator;
}

这个问题最终在Java 9中得到了正确的修复。看到javafx.stage.Window.getWindows ()

返回一个包含对当前显示的JavaFX的引用的列表窗户列表不可修改-尝试修改此列表会导致UnsupportedOperationException被抛出吗运行时。

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

最新更新