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.

Maven
<dependency>
    <groupId>io.quarkiverse.fx</groupId>
    <artifactId>quarkus-fx</artifactId>
    <version>0.5.2</version>
</dependency>
Gradle
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.

Loading FXML with injected 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();
}
Controller
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 :

Custom main
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 the Application is created and available,

  • FxPostStartupEvent indicates that the Application is ready as well as the Stage 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

Configuration property

Type

Default

Root location for fx resources (.fxml)

Environment variable: QUARKUS_FX_FXML_ROOT

string

/

Root location for style resources (.css)

Environment variable: QUARKUS_FX_STYLE_ROOT

string

/

Root location for bundle resources (.properties)

Environment variable: QUARKUS_FX_BUNDLE_ROOT

string

/