I have a class which calls a super constructor. The super class loads an FXML wrapper layout, and then another FXML layout as a child of an element within the wrapper, as so:
// Reference 'outer' FXML
URL outer_url = getClass().getResource("/main/resources/fxml/RootNode.fxml");
FXMLLoader outer_loader = new FXMLLoader(outer_url);
outer_loader.setRoot(this);
outer_loader.setController(this);
// Reference 'inner' FXML
URL inner_url = getClass().getResource(fxml_path);
FXMLLoader inner_loader = new FXMLLoader(inner_url);
try {
outer_loader.load();
/* The root of inner_loader is a component of outer_loader FXML,
* thus outer_loader.load() must be called first. */
inner_loader.setRoot(outer_loader.getNamespace().get("vbox_center"));
inner_loader.setController(controller);
inner_loader.load();
} catch (IOException e) {
e.printStackTrace();
}
I need the class to be the controller of inner_loader. Is this possible? I tried passing a reference to the class through the super constructor, however I cannot reference 'this' before the super constructor is called.
Any ideas? Thanks in advance.
EDIT: I also tried specifying the controller directly through the inner FXML file, however this caused problems.
EDIT 2: I forgot to specify, the superclass which loads the two FXML layouts is inherited by multiple nodes, which is why I cannot just create an instance of the Controller and pass it directly to inner_loader. I need to (somehow) pass an instance reference to the superclass and use that as the controller.


this) is of course an instance of its own class, and consequently also of the superclass. You could passthis, which would be strange because you would be using the same object as the controller for two different FXML files, and theinitialize()method (if there is one) would be called twice.vbox_centervia the loader's namespace. Sincethisis the controller, it should be injected via@FXMLat that point.