Multiple JavaFX stages in fullscreen mode

有些话、适合烂在心里 提交于 2020-01-02 01:23:27

问题


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?


回答1:


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();


来源:https://stackoverflow.com/questions/13030556/multiple-javafx-stages-in-fullscreen-mode

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