Load FXML and Controller - XDean/javafx-spring-boot GitHub Wiki
In javafx-spring-boot, controllers are managed by spring context. So that you can use any feature of spring-boot in your controller.
To convert your origin controller to sring-fx controller, the only thing need to do is to add the annotation @FxController
@FxConroller(fxml="/your.fxml")
public class YourController {
...
}
Now you can enjoy spring feature in the controller.
To load the FXML and controller, you don't need care about the FxmlLoader
any more. Just inject it!
public class OtherControllerOrApplication{
@Inject
YourController yc;
}
Now your.fxml
has been loaded and YourController
has been injected.
If you also interested in the root element, you can use FxmlResult
instead of the raw controller class
public class OtherControllerOrApplication{
@Inject
FxmlResult<YourController, HBox> result;
}
Now you can get both controller and root element from the FxmlResult
!