我在AWT中看到了一個方法:java.awt.Window.getWindows()
。 在JavaFx中,是否有任何方法可以獲得所有窗口JavaFx應用程序?如何獲得所有頂級窗口javafx?
謝謝,
我在AWT中看到了一個方法:java.awt.Window.getWindows()
。 在JavaFx中,是否有任何方法可以獲得所有窗口JavaFx應用程序?如何獲得所有頂級窗口javafx?
謝謝,
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;
}
這已經在Java 9中得到了最終修正。請參見javafx.stage.Window.getWindows()
返回包含對當前顯示的JavaFX 窗口的引用的列表。該列表不可修改 - 嘗試修改此列表 將導致在運行時拋出UnsupportedOperationException。
爲涉及StageHelper
或FXRobotHelper
其他解決方案不再可能,因爲這些在com.sun.javafx
包,它不再能夠訪問存在這是Java 9是必不可少的。
該方法僅在當前進程中列出一個Window JavaFX。請爲我的結果發表評論? – 2013-03-07 13:21:49
'java.awt.Window.getWindows()'的工作方式。它返回jre中的所有窗口。 – gontard 2013-03-07 13:23:49
@ gontard不,它不。我打開了幾個javafx窗口,但awt.Window方法仍然返回一個空數組。 – Renato 2014-03-29 12:20:05