2013-03-06 63 views

回答

6

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

虽然有脏和短期方式:

浏览source code of 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; 
} 
+0

该方法仅在当前进程中列出一个Window JavaFX。请为我的结果发表评论? – 2013-03-07 13:21:49

+0

'java.awt.Window.getWindows()'的工作方式。它返回jre中的所有窗口。 – gontard 2013-03-07 13:23:49

+0

@ gontard不,它不。我打开了几个javafx窗口,但awt.Window方法仍然返回一个空数组。 – Renato 2014-03-29 12:20:05

8

为javafx8运行java8 使用

FXRobotHelper.getStages() 
or 
StageHelper.getStages() 

这将检索所有阶段基本上是一个窗口本身(它扩展了Window类)

+0

这似乎没有找到用controlsfx创建的顶级对话框... – Adam 2014-11-06 11:28:24

+0

我想通过使用这两种方法知道差异在哪里。谢谢 – Davide 2017-03-10 18:54:10

1

这已经在Java 9中得到了最终修正。请参见javafx.stage.Window.getWindows()

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

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