Multiple JavaFX stages in fullscreen mode

无人久伴 提交于 2019-12-05 02:12:40

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();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!