How to pass parameters to JavaFX application?

后端 未结 8 573
温柔的废话
温柔的废话 2020-11-28 13:49

I am running my JavaFX application like this:

public class MainEntry {
    public static void main(String[] args) {
        Controller controller = new Contr         


        
8条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 14:24

    Starting with JavaFX 9 you can trigger the launch of the JavaFX platform "manually" using the public API. The only drawback is that the stop method is not invoked the way it would be in application started via Application.launch:

    public class MainEntry {
        public static void main(String[] args) {
            Controller controller = new Controller();
    
            final MainStage mainStage = new MainStage(controller);
            mainStage.init();
    
            Platform.startup(() -> {
                // create primary stage
                Stage stage = new Stage();
    
                mainStage.start(stage);
            });
        }
    }
    

    The Runnable passed to Platform.startup is invoked on the JavaFX application thread.

提交回复
热议问题