Annotating fields with the @FXML annotation.

The fx:id attribute is a unique identifier of a UI element in FXML that allows the component to be accessed from the controller. The variable name in the controller must match the fx:id. Fields annotated with @FXML will be automatically initialized.

Example:

FXML Java

<TextField fx:id="usernameField"/>

@FXML
private TextField usernameField;

Annotating methods with the @FXML annotation.

Action method – Event handlers

The attributes onAction, onMouseClicked, etc., connect an FXML event to a method in the Controller. The method must exist in the controller, be annotated with @FXML, and have a void return type.

FXML Java

<Button text="Login" onAction="#onLogin"/>

@FXML
private void onLogin() {
    System.out.println("The button is pressed.");
}

This site uses Just the Docs, a documentation theme for Jekyll.