I am testing and discovering JavaFX.
In JavaFX FXML documentation about controllers, it is said that if the controller has a public void initialize()
method, it is called once the FXML graph is loaded.
Is it possible to do something similar, but from the FXML file in a script way? I tried something like that, but initialize()
is not called at all.
<?xml version="1.0" encoding="UTF-8"?>
<?language javascript?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.AnchorPane?>
<AnchorPane xmlns:fx="http://javafx.com/fxml">
<fx:script>
importClass(java.lang.System);
function initialize() {
System.out.println('hello');
}
</fx:script>
<Button text="Button" />
</AnchorPane>
Do I miss something, or is just not possible to do that from the FXML file?
Is there a kind of workaround so the FXML file can embed some codes that will automatically execute after it is loaded (without using an external Java controller file)?