I saw a method in AWT: java.awt.Window.getWindows()
.
In JavaFx, is there any method to get all window JavaFx application?
Thanks,
This has finally been fixed properly in Java 9. See javafx.stage.Window.getWindows()
Returns a list containing a reference to the currently showing JavaFX windows. The list is unmodifiable - attempting to modify this list will result in an UnsupportedOperationException being thrown at runtime.
This is essential in Java 9 as the other solutions involving StageHelper
or FXRobotHelper
are no longer possible as these exist in com.sun.javafx
package which can no longer be accessed.
for javafx8 running java8 use
FXRobotHelper.getStages()
or
StageHelper.getStages()
This will retrieve all Stages which is essentially a Window itself ( it extends Window class)
AFAIK, there is still no proper way to do this.
Although there is a dirty and short term way :
Browsing the source code of javafx.stage.Window, there is a static method which seems to do what you are expecting : javafx.stage.Window#impl_getWindows()
.
But there is a bunch of disclaimers :
/**
* 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;
}