How to get all javafx top level windows?

I saw the method in the AWT: java.awt.Window.getWindows(). Is there any method in JavaFx to get the whole JavaFx application window?

Thank,

+5
source share
3 answers

AFAIK, there is still no proper way to do this.

Although there is a dirty and short-term way:

Viewing the source codejavafx.stage.Window , there is a static method, which seems to be doing what you expect: javafx.stage.Window#impl_getWindows().

But there are a bunch of failures:

/**
 * 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;
}
+6
source

for javafx8 running java8 use

FXRobotHelper.getStages()
 or 
StageHelper.getStages()

This will retrieve all the steps that are essentially the window itself (it extends the Window class)

+8
source

Java 9. . javafx.stage.Window.getWindows()

Returns a list containing a link to the currently displayed JavaFX window. The list cannot be modified - an attempt to change this list will throw an UnsupportedOperationException at runtime.

This is important in Java 9 because other solutions including StageHelperor FXRobotHelperare no longer possible because they exist in a package com.sun.javafxthat can no longer be accessed.

+1
source

All Articles