我有一个包含两个阶段的应用程序,应该在全屏模式下在两个不同的屏幕上显示.我设法将这两个阶段放在单独的屏幕上,并试图在每个舞台上将全屏属性设置为true,但只显示它们没有装饰.它始终是具有全屏属性设置的全屏属性,以全屏模式显示.
JavaFX 2.2中是否有可能同时在全屏模式下拥有多个阶段?
我也遇到了这个问题,我找到了一个简单的解决方案(解决方法):
首先,我们需要主监视器的id:
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;
}
}
Run Code Online (Sandbox Code Playgroud)
在此之后,我们初始化并显示初级阶段.在主监视器上执行此操作非常重要(用于隐藏任务栏和此类事物).
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();
Run Code Online (Sandbox Code Playgroud)
现在解决方法部分.我们为其他监视器创建阶段:
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();
Run Code Online (Sandbox Code Playgroud)