Quarkus FX
This extension allows you to use Java FX in your Quarkus application.
Installation
In order to use this extension, you need to add the io.quarkiverse.fx:quarkus-fx
dependency to your project.
<dependency>
<groupId>io.quarkiverse.fx</groupId>
<artifactId>quarkus-fx</artifactId>
<version>0.5.2</version>
</dependency>
dependencies {
implementation 'io.quarkiverse.fx:quarkus-fx:0.5.2'
}
Usage
The extension allows using cdi features in JavaFX controller classes.
The FXMLLoader
is made a CDI bean and can be injected in your application.
FXMLLoader
@Inject
FXMLLoader fxmlLoader;
public void load() {
Parent root = this.fxmlLoader.load(this.getClass().getResourceAsStream("/app.fxml"));
Scene scene = new Scene(root);
stage.setScene(scene);
stage.show();
}
public class MyFxmlController {
@Inject
MyService myService;
@FXML
private void onButtonClicked() {
this.myService.doSomething();
}
}
Startup
The application will automatically be launched (thanks to a call to javafx.application.Application::launch
) when the extension is present.
If you need to customize the launch, you can provide a custom @QuarkusMain
, such as :
package io.quarkiverse.fx.fxapp;
import io.quarkiverse.fx.FxApplication;
import io.quarkus.runtime.QuarkusApplication;
import io.quarkus.runtime.annotations.QuarkusMain;
import javafx.application.Application;
@QuarkusMain
public class QuarkusFxApplication implements QuarkusApplication {
@Override
public int run(final String... args) {
Application.launch(FxApplication.class, args);
return 0;
}
}
When the application is started, two main events are fired in sequence :
-
FxApplicationStartupEvent
indicates that theApplication
is created and available, -
FxPostStartupEvent
indicates that theApplication
is ready as well as theStage
instance.
void onApplicationStartup(@Observes final FxApplicationStartupEvent event) {
Application application = event.getApplication();
}
void onPostStartup(@Observes final FxPostStartupEvent event) {
Stage stage = event.getPrimaryStage();
}
Injecting HostServices
The HostServices
instance which is obtained via Application::getHostServices
can also be injected by using the @Inject
annotation.
@ApplicationScoped
public class MyBean {
@Inject
HostServices hostServices;
}
Properties
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Type |
Default |
|
---|---|---|
Root location for fx resources (.fxml) Environment variable: |
string |
|
Root location for style resources (.css) Environment variable: |
string |
|
Root location for bundle resources (.properties) Environment variable: |
string |
|