Here is an example FXML:
https://github.com/SnakeDoc/superD/blob/master/src/com/vanomaly/superd/view/MainWindow.fxml
Here is an example controller class:
As you will notice, in your FXML you can specify a Controller. Or, like in this example:
https://github.com/SnakeDoc/superD/blob/master/src/com/vanomaly/superd/Main.java
You can specify your controller in java code during the start up of your JavaFX application.
It doesn't matter which, but don't do both (you will get an error).
Then, in your controller, you can use the @FXML
annotation to link that variable to the correct GUI control in your FXML that has the same fx:id
as the variable name (see examples again).
Then you can just use that variable like any other GUI control. :)
Example:
@FXML private Label targetLabel;
Is defined in the controller.
And in the FXML, there is:
<Label fx:id="targetLabel" layoutX="26.0" layoutY="16.0" styleClass="contrast-label" text="Target(s) :" />
Notice how the fx:id
is the same as the variable name? This tells JavaFX to link them (they are the same).