Skip to content

quarkiverse/quarkus-fx

Repository files navigation

quarkus-fx

Version

All Contributors

This Quarkus extension allows you to use JavaFX in your Quarkus application.
It will allow component injection in FX Controllers and will allow you to use CDI events to register on primary stage creation.

Live reload is still problematic and will be studied in the future.

You will be able to register on primary stage creation event via such code example.

public class QuarkusFxApp {

  @Inject
  FXMLLoader fxmlLoader;

  public void start(@Observes final FxStartupEvent event) {
    try {
      InputStream fxml = this.getClass().getResourceAsStream("/app.fxml");
      Parent fxmlParent = this.fxmlLoader.load(fxml);

      Stage stage = event.getPrimaryStage();
      
      Scene scene = new Scene(fxmlParent);
      stage.setScene(scene);
      stage.show();

    } catch (IOException e) {
      // Handle error
    }
  }
}

To load multiple FXML files, you can use :

@Inject
Instance<FXMLLoader> fxmlLoader;

Also, setting the location is required by some use cases (use of relative paths in FXML)

FXMLLoader loader = this.fxmlLoader.get();
// Set location for relative path resolution
loader.setLocation(xxx);

For some sample apps and usage, check the samples/ directory.

Contributors ✨

Thanks goes to these wonderful people (emoji key):

Clément de Tastes
Clément de Tastes

💻 🚧
Ghazy Abdallah
Ghazy Abdallah

💻
Scott M Stark
Scott M Stark

💻

This project follows the all-contributors specification. Contributions of any kind welcome!