Search code examples
javafxstage

How to identify opened window is on which monitor while using primary and secondary monitors: JavaFx


I am using multiple monitors, before I open popup from main window I need to check the main window is currently active(opened) on which monitor. How can check in JavaFx.


Solution

  • Use Screens.getScreensForRectangle. Using the bounds of your window you should be able to get a list of the screens used to display it's area:

    List<Screen> windowScreens = Screens.getScreensForRectangle(window.getX(), window.getY(),
                                                                window.getWidth(), window.getHeight());