I'm pretty new to Java FX
and fxml
templates, I know that to access to an object's methods you need to use setOnAction
and declare a specific method into the controller class.
Is there a way to access to its methods from code without using setOnAction
?
Example what I want to do:
FXML Document
<?import javafx.scene.control.Label?>
<?import javafx.scene.layout.VBox?>
<VBox maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.111" xmlns:fx="http://javafx.com/fxml/1" fx:controller="package.Controller">
<children>
<Label fx:id="myLabel" text="Label" />
</children>
</VBox>
Controller class
public class Controller {
@FXML
Label myLabel;
public Controller() {
this.mylabel = new Label();
//some code here
myLabel.setText("modified text 0");
//some code here
myLabel.setText("modified text 1");
}
}
Is that possible in some way by not using setOnAction
custom method?