使用JavaFX Scene Builder 2.0同时显示两个窗口 [英] Display two windows at the same time using JavaFX Scene Builder 2.0

查看:465
本文介绍了使用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.

我正在使用JavaFx Scene Builder 2.0 NetBeans 8.0.1

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

是否可以执行此操作?如果是这样,怎么办呢?

is it possible to do this? if so, how it can be done ?

谢谢!

推荐答案

通过屏幕我假设你的意思是窗口。

By "screen" I assume you mean "window".

只需在 start()中创建第二个阶段方法并与初级阶段完全相同:

Just create a second stage in your start() method and do exactly the same with it as you do your primary stage:

public class MyApp extends Application {

    @Override
    public void start(Stage primaryStage) {

        Stage anotherStage = new Stage();

        try {
            FXMLLoader loader = new FXMLLoader(...); // FXML for primary stage
            Parent root = loader.load();
            Scene scene = new Scene(root);
            primaryStage.setScene(scene);
            primaryStage.show();

            FXMLLoader anotherLoader = new FXMLLoader(...) ; // FXML for second stage
            Parent anotherRoot = anotherLoader.load();
            Scene anotherScene = new Scene(anotherRoot);
            anotherStage.setScene(anotherScene);
            anotherStage.show();

        } catch (Exception exc) {

            exc.printStackTrace();

        }
    }

    public static void main(String[] args) { launch(args); }
}

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

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