Quarkus FX

This extension allows you to use Java FX to 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.2.0</version>
</dependency>

Gradle

dependencies {
    implementation 'io.quarkiverse.fx:quarkus-fx:0.2.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.

@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, you can get obtain access to the primary Stage instance by observing the FxStartupEvent CDI event :

void onStart(@Observes final FxStartupEvent event) {
  Stage stage = event.getPrimaryStage();
}