9

I have an application that contains two stages which should be shown on two different screens both in fullscreen mode. I managed to position the two stages on seperate screens, and tried to set the fullscreen property to true on each Stage, but only of them is shown without decoration. It is always the one that has the fullscreen property set last that is shown in fullscreen mode.

Is it not possible in JavaFX 2.2 to have multiple stages in fullscreen mode at the same time?

4

1 回答 1

9

I also ran into this problem and I found an easy solution(workaround):

First we need the id of the primary monitor:

int primaryMon;
Screen primary = Screen.getPrimary();
for(int i = 0; i < Screen.getScreens().size(); i++){
    if(Screen.getScreens().get(i).equals(primary)){
        primaryMon = i;
        System.out.println("primary: " + i);
        break;
    }
}

After this we init and show the primary stage. It is important to do this on the primary monitor (for hiding taskbars and such things).

Screen screen2 = Screen.getScreens().get(primaryMon);
Stage stage2 = new Stage();
stage2.setScene(new Scene(new Label("primary")));
//we need to set the window position to the primary monitor:
stage2.setX(screen2.getVisualBounds().getMinX());
stage2.setY(screen2.getVisualBounds().getMinY());
stage2.setFullScreen(true);
stage2.show();

Now the workaround part. We create the stages for the other monitors:

Label label = new Label("monitor " + i);
stage.setScene(new Scene(label));
System.out.println(Screen.getScreens().size());
Screen screen = Screen.getScreens().get(i); //i is the monitor id

//set the position to one of the "slave"-monitors:
stage.setX(screen.getVisualBounds().getMinX());
stage.setY(screen.getVisualBounds().getMinY());

//set the dimesions to the screen size:
stage.setWidth(screen.getVisualBounds().getWidth());
stage.setHeight(screen.getVisualBounds().getHeight());

//show the stage without decorations (titlebar and window borders):
stage.initStyle(StageStyle.UNDECORATED);
stage.show();
于 2013-01-08T20:25:08.687 回答