WHAT I HAVE is a standard JavaFX application: Main.java, MainController.java & main.fxml
. To add custom component, I created CustomComponentController.java
and custom_component_controller.fxml
.
PROBLEM is that in CustomComponentController
methods I need to reference other methods and standard components from MenuController
. I add public static MainController mc;
to MainController
class body, so that it can be seen from CustomComponentController
(MainController.mc.neededMethod()
). Then I try to pass everything to it in MainController.initialize()
method (mc = this;
) - when debugging this breakpoint, I see this
full of components instances, but mc
remains with null components afterwards.
QUESTION is how to reference the running instance of MainController
to use its components and methods in other classes and to crossreference different custom components from each other? How to clean MainController
code from event handlers and assistance methods of components by moving it all to component's own class?
I tried the following approaches, but found no way to make them work without errors:
Accessing FXML controller class
How can I access a Controller class in JavaFx 2.0?
JavaFX 2.0 + FXML. Updating scene values from a different Task
JavaFX 2.2 -fx:include - how to access parent controller from child controller