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.9.0</version>
</dependency>
dependencies {
implementation 'io.quarkiverse.fx:quarkus-fx:0.9.0'
}
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;
}
Accessing the primary stage
The primary Stage
can be accessed by injecting FxViewRepository
.
@ApplicationScoped
public class MyBean {
@Inject
FxViewRepository viewRepository;
void doSomething() {
Stage primaryStage = this.viewRepository.getPrimaryStage();
primaryStage.setTitle("App Title");
}
}
Properties
Configuration property fixed at build time - All other configuration properties are overridable at runtime
Configuration property |
Type |
Default |
---|---|---|
Root location for fx views. The extension will look for fx views from this root directory. Environment variable: |
string |
|
Stylesheet live reload strategy. Environment variable: |
|
|
Location for source resources (allowing stylesheet live reload in dev mode) Environment variable: |
string |
|
Location for target resources (where resources files are located after build) In dev mode, if stylesheet reload is activated, app will use stylesheet from sources instead of the ones in target and monitor changes Environment variable: |
string |
|