This discussion is archived
4 Replies Latest reply: Nov 11, 2012 8:33 AM by J. Ishikawa RSS

Determine current Screen

J. Ishikawa Newbie
Currently Being Moderated
Hi!

I have multiple screens...

How can I determine on which screen my current application window (stage) is located?
  • 1. Re: Determine current Screen
    shakir.gusaroff Expert
    Currently Being Moderated
            Screen screenX = Screen.getPrimary();
            ObservableList<javafx.stage.Screen> screens = javafx.stage.Screen.getScreens();
            for (javafx.stage.Screen screen : screens) {
                if (screenX.equals(screen)) {
                    System.out.println("primary screen is: " + screen);
                }
                
                else  
                {System.out.println("Secondary screen is:  " + screen);}
              }
  • 2. Re: Determine current Screen
    J. Ishikawa Newbie
    Currently Being Moderated
    @Shakir
    Thank you for your reply, but your answer doesn't solve my problem to determine, on which screen my JavaFX application is currently located.

    To clarify the problem further...
    When a JavaFX application is loaded, its shown on the primary screen. But when the application window is moved to another screen, how to detect this?

    Edited by: user634289 on Nov 10, 2012 11:50 AM
  • 3. Re: Determine current Screen
    lgringo Newbie
    Currently Being Moderated
    Hi, you could use the static method [url http://docs.oracle.com/javafx/2/api/javafx/stage/Screen.html#getScreensForRectangle%28double,%20double,%20double,%20double%29]getScreensForRectangle

    Exemple :
    List<Screen> screens = Screens.getScreensForRectangle(stage.getX(),stage.getY(),stage.getWidth(),stage.getHeight());

    As your window can spread accross multiple screens, the result is a list.

    Edited by: lgringo on 11 nov. 2012 16:44
  • 4. Re: Determine current Screen
    J. Ishikawa Newbie
    Currently Being Moderated
    @lgringo

    Thanks alot. This was the solution I was looking for. :)

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points