Starting a second JavaFX Application

后端 未结 1 759
花落未央
花落未央 2021-01-03 05:50

I\'m trying to launch a JavaFx application from within a JavaFx application, but it looks like Application.launch() can only be called once. Does this mean I have to start a

1条回答
  •  借酒劲吻你
    2021-01-03 06:28

    If you want to execute another JavaFX application in the same JVM you can just create instance of it, manually create Stage and call Application#start()

    public void runAnotherApp(Class anotherAppClass) throws Exception {
        Application app2 = anotherAppClass.newInstance(); 
        Stage anotherStage = new Stage();
        app2.start(anotherStage);
    }
    

    N.B.: it wouldn't work if you use special features of standard initialization in anotherApp, e.g. Application.init() or Application.getParameters()

    0 讨论(0)
提交回复
热议问题