同时在“全屏”上显示两个窗口。使用JavaFx Scene Builder 2.0 [英] Display two windows at the same time "on fullscreen" with JavaFx Scene Builder 2.0

查看:314
本文介绍了同时在“全屏”上显示两个窗口。使用JavaFx Scene Builder 2.0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个迷你应用程序,我需要同时向用户显示2个窗口但是在全屏幕上(该应用程序将在双屏幕上为用户制作)。

I'm working on a mini application where I need to display to users 2 windows at the same time but on Fullscreen (the application will be made for users on dual screen).

我在NetBeans 8.0.1上使用JavaFx Scene Builder 2.0

I'm working with JavaFx Scene Builder 2.0 on NetBeans 8.0.1

我尝试了这个,但只有第二个窗口显示在全屏上。

I tried this but only the second window gets displayed on fullscreen.

public void showTwoScreens() {
    try {
        Parent root = FXMLLoader.load(getClass().getResource("ClientsOperationsWindow.fxml"));
        Scene scene = new Scene(root);

        globalStage.setScene(scene);
        globalStage.setFullScreen(true);
        globalStage.setResizable(true);
        globalStage.show();

        Stage anotherStage = new Stage();
        Parent secondRoot = FXMLLoader.load(getClass().getResource("ClientsSearchWindow.fxml"));

        Scene secondStage = new Scene(secondRoot);
        secondStage.setScene(anotherScene);
        secondStage.setFullScreen(true);
        secondStage.show();

    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
}

是否可以在全屏显示两个窗口?

is it possible to display two windows on fullscreen ?

谢谢!

推荐答案

我认为你不能设置两个同时在两个显示器中全屏显示,但你可以通过强制舞台尺寸获得相同的结果。

I think you can't set two stages in fullscreen in two monitors at the same time, but you can get the same result, by forcing the stage dimensions.

为此,我们将使用 javafx.stage.Screen ,以获取连接的每个不同监视器的特征。然后我们将fxml文件加载到每个场景,并在其舞台上显示每个场景。使用 Screen.getBounds()我们现在将矩形的原点和尺寸引用到主屏幕。所以我们用这些矩形的边界设置每个阶段边界。最后,我们将风格设置为未修饰。现在唯一缺少的功能是退出全屏模式键组合。

For that, we'll use javafx.stage.Screen, to get the characteristics for each of the different monitors connected. Then we load the fxml files to each scene, and display each scene on its stage. With Screen.getBounds() we now the origin and dimensions of the rectangle, refered to the primary screen. So we set each stage bounds with the bounds of these rectangles. Finally we set the style to undecorated. The only feature missing now is an exit "fullscreen" mode key combination.

private Screen secondaryScreen;

@Override
public void start(Stage primaryStage) throws IOException {

    Screen primaryScreen = Screen.getPrimary();

    Parent root = FXMLLoader.load(getClass().getResource("Screen1.fxml"));
    Scene scene = new Scene(root);
    primaryStage.setScene(scene);
    Rectangle2D bounds = primaryScreen.getBounds();
    primaryStage.setX(bounds.getMinX());
    primaryStage.setY(bounds.getMinY());
    primaryStage.setWidth(bounds.getWidth());
    primaryStage.setHeight(bounds.getHeight());
    primaryStage.initStyle(StageStyle.UNDECORATED);
    primaryStage.show();

    // look for a second screen
    Screen.getScreens().stream()
            .filter(s->!s.equals(primaryScreen))
            .findFirst().ifPresent(s->secondaryScreen = s);

    if(secondaryScreen!=null){
        Stage secondaryStage = new Stage();
        Parent root2 = FXMLLoader.load(getClass().getResource("Screen2.fxml"));
        Scene scene2 = new Scene(root2);
        secondaryStage.setScene(scene2);
        Rectangle2D bounds2 = secondaryScreen.getBounds();
        secondaryStage.setX(bounds2.getMinX());
        secondaryStage.setY(bounds2.getMinY());
        secondaryStage.setWidth(bounds2.getWidth());
        secondaryStage.setHeight(bounds2.getHeight());
        secondaryStage.initStyle(StageStyle.UNDECORATED);
        secondaryStage.show();  
    } 
}

这篇关于同时在“全屏”上显示两个窗口。使用JavaFx Scene Builder 2.0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆