public class SimpleController
extends java.lang.Object
The method that is annotated by @PostContruct will be called when all injections are finished.
In this first example we will only use @FXML to inject FXML UI components to the controller.
In addition DataFX action handling is introduced in this example. The view contains a button named actionButton. Once this button is clicked, the onAction() method will be executed. To do so DataFX contains two annotation: - The @ActionTrigger annotation annotates a UI component that will trigger an action. Each action in DataFX is defined by a unique id, which is passed as the value of the @ActionTrigger annotation In this example the "myAction" id is used. The id must be unique in view controller. - To handle the action a method of the controller should be annotated with the @ActionMethod annotation. The value of this annotation must be the unique id of the defined action. Therefore @ActionMethod("myAction") is used here. The method will be called in the JavaFX Application Thread
As you will see later there are other types of actions than simply calling a method. These will be shown later in other tutorial. For now the most important point is that a component that is annotated with @ActionTrigger can trigger a method that is annotated with {link @io.datafx.controller.flow.action.ActionMethod} if both annotations define the same unique action id. So once the actionButton in this example is clicked the onAction() method will be called and the text of the label will change.
Note: This example is quite easy and normally you could define the action binding by only one line of Java code in the init() method: actionButton.setOnAction((e) -> onAction()); So why are these annotations used here? As you will see in further tutorials that are more complex than this one it will make sense to use the annotations to provide more readable code.
| Constructor and Description |
|---|
SimpleController() |
| Modifier and Type | Method and Description |
|---|---|
void |
init() |
void |
onAction() |