Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaFx: how to reference main Controller class instance from CustomComponentController class?
    primarykey
    data
    text
    <p>WHAT I HAVE is a standard JavaFX application: <code>Main.java, MainController.java &amp; main.fxml</code>. To add custom component, I created <code>CustomComponentController.java</code> and <code>custom_component_controller.fxml</code>.</p> <p>PROBLEM is that in <code>CustomComponentController</code> methods I need to reference other methods and standard components from <code>MenuController</code>. I add <code>public static MainController mc;</code> to <code>MainController</code> class body, so that it can be seen from <code>CustomComponentController</code> (<code>MainController.mc.neededMethod()</code>). Then I try to pass everything to it in <code>MainController.initialize()</code> method (<code>mc = this;</code>) - when debugging this breakpoint, I see <code>this</code> full of components instances, but <code>mc</code> remains with null components afterwards.</p> <p>QUESTION is how to reference the running instance of <code>MainController</code> to use its components and methods in other classes and to crossreference different custom components from each other? How to clean <code>MainController</code> code from event handlers and assistance methods of components by moving it all to component's own class?</p> <p>I tried the following approaches, but found no way to make them work without errors:</p> <p><a href="https://stackoverflow.com/questions/10751271/accessing-fxml-controller-class">Accessing FXML controller class</a></p> <p><a href="https://stackoverflow.com/questions/10240471/how-can-i-access-a-controller-class-in-javafx-2-0">How can I access a Controller class in JavaFx 2.0?</a></p> <p><a href="https://stackoverflow.com/questions/10107829/javafx-2-0-fxml-updating-scene-values-from-a-different-task/10108788#10108788">JavaFX 2.0 + FXML. Updating scene values from a different Task</a></p> <p><a href="https://stackoverflow.com/questions/15004365/javafx-2-2-fxinclude-how-to-access-parent-controller-from-child-controller">JavaFX 2.2 -fx:include - how to access parent controller from child controller</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload