Good day. I read that the Controller constructor is called before the initialize (...) method. But I do not know how to pass parameters to the constructor. The only way I know is this:

FXMLLoader loader = new FXMLLoader(...); TestController testController = new TestController(some paremetrs); loader.setController(controller); loader.load(); 

But I don’t like it for certain reasons, maybe there is a way to make it somehow more correct and beautiful?

    1 answer 1

    Unfortunately, it’s impossible to pass through the constructor.

    One possible solution is to pass the parameters through the setter (s) after the controller has been loaded and initialized:

     FXMLLoader loader = new FXMLLoader(...); loader.load(); TestController testController = loader.getController(); testController.set(some parameters); 

    True, it strongly depends on your controller logic and it may be inconvenient to complain about new parameters.

    • Thanks for the info - ProstoCoder