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.
if controller doesn't need external objects initialize state before calling own
initialize(), in other words controller class hasno-arg constructor(or callfxmlloader'ssetcontrollerfactory(), provide implementation of how controller should initialized) , manageablefxmlloader, gofx:controller, set in fxml file itself.fxmlloaderload controller , callinitialize()if there such method. default way of linking controller , fxml file.if controller has constructor
at least 1 argumentor in controller'sinitialize()requires access fields must initialized externally (not within controller class), manually manage controller. create instance of it, other java class, initialize required , callsetcontroller()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
Post a Comment