Display two windows at the same time using JavaFX Scene Builder 2.0

霸气de小男生 提交于 2019-12-06 06:35:50

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

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