Calling code when loading FXML
In the controller class, define a method:
@FXML
protected void initialize(URL location, Resources resources)
This method will automatically be called by FXMLLoader when the FXML file is loaded.
There is a sample in Introduction to FXML (I just reproduced it here, slightly modified).
FXML
<VBox fx:controller="com.foo.MyController"
xmlns:fx="http://javafx.com/fxml">
<children>
<Button fx:id="button" text="Click Me!"/>
</children>
</VBox>
Java
package com.foo;
public class MyController implements Initializable {
@FXML private Button button;
@FXML
protected void initialize(URL location, Resources resources) {
button.setOnAction(new EventHandler<ActionEvent>() {
@Override
public void handle(ActionEvent event) {
System.out.println("You clicked me!");
}
});
}
}
initialize () method without location and URL
, initialize , , , , Initializable , FXML :
public void initialize()
.:
,
, FXML, FXML ( , FXMLLoader FXMLLoader , , , ). , " , TextFields", , FXML ( , ).