For instance at the top of my program before the start method I have
Then in my start method I can just start working directly with that table like this..?
Knute Snortum wrote:This code injects an object reference tblMainParts into the code, so no, you don't have to (and you should not) create the object with new. The fx:id in SceneBuilder connects the FXML widget with the code's variable identifier. Make sense?
It does, thank you. I was having some issues getting my table to populate - and thought maybe I was misunderstanding something there. So it turns out I needed to create another controller as the main.java file isn't a good file to use as a controller if it's your main entry point. So I created a separate controller - data still isn't populating the way I need it to but it eliminated some of the issues I was having.
See the Makery JavaFX tutorial PersonOverviewController java and fxml files for examples:
In general, anything you annotate with @FXML is created and injected by the FXMLLoader and you should never directly assign the reference to a new object or any other object created by your application.
And yes, you are correct, the main Application class should never be also be a Controller class. The Java/JavaFX launchers create an instance of an Application class. Any given application should only have a single Application class instance. The FXMLLoader creates instances of the Controller classes. So if you make an Application class also a controller, two instances of it will be created, one by the Java/JavaFX launcher and another by the FXMLLoader, this will almost certainly lead to confusion and bugs.