Loading multiple fxml in javafx

人盡茶涼 提交于 2019-12-05 13:36:57

Every .fxml that you load can have its own controller. Every controller can have custom action and loading code just like your main one does.

Basically, JavaFX is modular. If something is possible in your main pane, then it's possible in all its children too.

Generally, in UI-based frameworks, it is a wise idea to keep a hierarchy of controllers that mirrors the hierarchy of their respective components. If you want to get the child controller for the child element (for example, in order to pass the reference to the parent controller), then you can't rely on the FXML.load() shortcut, you have to use the longer syntax of:

FXMLLoader loader = new FXMLLoader(getClass().getResource("your.fxml"));
YourPaneType pane = loader.load();
YourControllerType controller = loader.getController();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!