如何获取对控制器类的引用?
这是我的代码片段.
Parent root = FXMLLoader.load(getClass().getResource("my.fxml"));
stage.setScene(new Scene(root, 500, 500));
MyController c = stage.getControllerInstance(); <-- HOW???
c.setATextValue("Hello world"); //Set initial value
stage.show();
Run Code Online (Sandbox Code Playgroud)
Controller类在FXX中的fx:controller属性中指定.实例将在后台自动创建.我需要访问该实例才能在表单中设置初始值.
我知道我可以在XML中设置初始值,但我需要在运行时设置它们.