问题描述
我是一个标准的JavaFX应用程序: c来调用它,用 CustomComponentController / code>' initialize()方法。通过向 reloadCustomComponents()方法添加以下内容来实现:
In main.fxml create primary component of the same type that CustomComponentController and with the only fx:id parameter. Replace primary component with your CustomComponentController by creating reloadCustomComponents() method and calling it from CustomComponentController's initialize() method. Do it by adding the following to reloadCustomComponents() method:
customComponentAnchorPane.getChildren()。remove(customComponent) ;
customComponentAnchorPane.getChildren().remove(customComponent);
customComponent = new customComponent();
customComponent = new customComponent();
customComponentAnchorPane.getChildren()。add(customComponent);
customComponentAnchorPane.getChildren().add(customComponent);
因此,所有组件都可以放置在 CustomComponentController 方法并在重复启动时重新加载。所有组件声明都保留在 MainController 类中,并且可以通过 MainController mc 引用访问。无需使用参数详细重复创建组件。
Thus all components can be placed outside CustomComponentController with all their methods and reloaded at the startup of the apllication. All component declarations stay in MainController class and can be reached through MainController mc reference. No duplicate creating of components in detail with parameters is needed.
这篇关于JavaFx:如何从CustomComponentController类中引用主控制器类实例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!