2013-03-06 39 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是必不可少的。

相關問題