java - Difference between initialized controllers and FXML linked controllers? -


until didn't know set controllers fx:controller in fxml file have relied on fxmlloader's setcontroller manage linking.

so, there reason use 1 on particular case overrideable initialize() method useful?

there no functional difference between 2 methods of setting controller fxml file. however, in terms of when use there slight distinction.

  1. if controller doesn't need external objects initialize state before calling own initialize(), in other words controller class has no-arg constructor (or call fxmlloader's setcontrollerfactory() , provide implementation of how controller should initialized) , manageable fxmlloader, go fx:controller , set in fxml file itself. fxmlloader load controller , call initialize() if there such method. default way of linking controller , fxml file.

  2. if controller has constructor at least 1 argument or in controller's initialize() requires access fields must initialized externally (not within controller class), manually manage controller. create instance of it, other java class, initialize required , call setcontroller() link controller fxml file. technique typically used custom controllers

for more details please have @ this: http://docs.oracle.com/javase/8/javafx/api/javafx/fxml/doc-files/introduction_to_fxml.html#custom_components


Comments

Popular posts from this blog

IF statement in MySQL trigger -

c++ - What does MSC in "// appease MSC" comments mean? -

javascript - Blogger related post gadget image Resize s72-c [ Need Expert Help ] -