Subcontroller not being injected into main controller

风流意气都作罢 提交于 2019-12-01 03:32:23

To use @FXML tag you have to provide fx:id.

Update your main.fxml:

<bottom>
    <fx:include fx:id="statusbar" source="statusbar.fxml" />
</bottom>

After that you can use next constants in your MainController.java:

@FXML
Label statusbar; // node itself
@FXML
private StatusBarController statusbarController; // controller

Note, that statusbarControlleris not a partialy lowercased class name, but fx:id + Controller word.

There seems to be a bug in netbeans 8.0 with nested fxmls as well. Cannot count on netbeans to create the nested fxml's controller object for you, it has to be manually inserted into your MainController. Every time the controller is updated in netbeans it gets wiped out so it can be kind of tedious. For this example that would be inserting the

@FXML private StatusBarController statusbarController;

line manually into the main controller in this case, then it works normally. Very useful for organizing large fxmls/controllers.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!