How to get all top level window javafx?

前端 未结 3 1212
忘了有多久
忘了有多久 2021-01-13 05:38

I saw a method in AWT: java.awt.Window.getWindows(). In JavaFx, is there any method to get all window JavaFx application?

Thanks,

相关标签:
3条回答
  • 2021-01-13 06:08

    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.

    0 讨论(0)
  • 2021-01-13 06:13

    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)

    0 讨论(0)
  • 2021-01-13 06:23

    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;
    }
    
    0 讨论(0)
提交回复
热议问题