JavaFx:What 如果我想在initialize()之后,场景展示之前做点什么,我该如何实现?

JavaFx:What if I want to do something after initialize(),before the scene show,how can I achieve this?

我想做点什么,在controller的initialize()方法完成后,但是在场景之前show.Is在场景显示之前会调用什么方法?我想在方法中放一些代码。

FXMLLoader loader = new FXMLLoader();
loader.setLocation(getClass().getResource("sample.fxml"));
AnchorPane pane = loader.load();
Scene gameScene = new Scene(pane);
//I load a secne above,the I will get the controller,set some properties,then,use the properties to read a file before the secene show.
GameUIController controller = loader.getController();
controller.setGameFileLoacation("game1.txt");//I set a property here.I want to use it to read game file,and load game,set some necessary UI.
primaryStage.setScene(gameScene);//this tow statement will show the scene.
primaryStage.show();

我无法将代码放入 initialize() 方法,因为它会在 fxml 文件加载时调用(当我还没有获取控制器时)。那么,我该怎么办?

非常感谢!

我找到的一个解决方案

 primaryStage.addEventHandler(WindowEvent.WINDOW_SHOWING, new  EventHandler<WindowEvent>()
    {
        @Override
        public void handle(WindowEvent window)
        {
            //Your code 
        }
    });

此事件发生在 window 之前。doc link