Michael Peremsky wrote:I thought that by tying the fxid to the object in the fxml, it was supposed to create an instance of the object on the load.
FXMLLoader.load() does normally trigger @FXML field injection.
But you might want to use the initialize() method for initializing the field component rather than the constructor. Most of my controllers don't even have explict constructors. The initialize() method is safe to access FXML injected stuff from (implement Initializable). Actually I'd also suggest using fx:controller in the FXML rather than setController() which is a bit unorthodox IMO. It's more common for me to see it done something like this (I often put the FXMLLoader parts into a utility class):
Safe to access injected fields after initialize():
> Task :TestFxml.main()
Cons: null
initialize: VBox[id=testingVb]
Just make sure your controller implements Initializable.
Gluon Scene Builder will set the fx:controller attribute for you if you select it on the Controller area of the left panel. Rarely needed to mess with FXML directly. Some/all IDEs have FXML plugins also which will automatically generate and correct your @FXML injected stuff, helps eliminate simple mistakes.