Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple JavaFX stages in fullscreen mode

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?

like image 798
jbiversen Avatar asked Oct 23 '12 12:10

jbiversen


1 Answers

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();
like image 200
rbs Avatar answered Oct 05 '22 23:10

rbs