JavaFX with CDI example project

Overview

javafx-cdi-example

JavaFX with CDI example.

Apache Java Development Kit 11

⚠️ In case you have a hi-resolution display and want to run the application on Ubuntu, make sure to pass an environment variable like GDK_SCALE=2to the application. Otherwise it will be unscaled. See Issue #643 for more details.

Features

The example application shows how to implement the most important parts of a real world JavaFX application. Most tutorials for JavaFX only show how to create a screen, but there is more than that.

This example has the following features included:

Based on Java 11 with JavaFX 13

The project is based on Java 11 and JavaFX.

Maven build

There is a fully configured Maven build that creates a ZIP archive that has a batch file (Windows) and a shell script (Linux) to start the application.

Github build

The project is ready configured to be build on Github. Simply copy the project generated by the below archetype to a fresh Github repository and you have an automated build out of the box.

It also sets the necessary arguments in case you want to run some GUI unit tests:

-Djava.awt.headless=true -Dtestfx.robot=glass -Dtestfx.headless=true 
-Dprism.order=sw -Dprism.text=t2k -Dtestfx.setup.timeout=2500

Contexts and Dependency Injection (CDI)

You can use @Inject annotations in your application controllers for injecting services, events and configuration.

@Singleton
@Loggable
public class ChildController implements Initializable {

    @FXML
    private Label labelResult;
    
    @Inject
    private Logger log;

    ...

}

Structuring an application with sub controllers

If you start with JavaFX it's not easy to figure out how to structure a larger application. See the JavafxCdiExampleController.java to see how a parent controller opens a child controller and passes some data to it.

@FXML
public void onOpenChildController(ActionEvent event) {
    final NodeControllerPair<ChildController> childCtrlPair = 
            NodeControllerPair.load(loaderInstance, ChildController.class);
    final ChildController childController = childCtrlPair.getController();
    childController.setProgressUI(progressUI);
    childController.setMessageDisplay(messageDisplay);
    borderPaneContent.setCenter(childCtrlPair.getParent());
}

Using tasks for handling long operations

There are often some operations that may take a while. You need to create a task for it. See the LongRunningTaskExample.java on how to do it. The task also emits some status information to the UI and blocks it.

Blocking UI during task execution

During execution of a long running task you most likely want to block the UI and show some progress indicator.

About dialog showing a version

Use the Maven version from the POM and the Git information inside the project to populate an About dialog.

Catching unexpected exceptions showing a dialog

Sometimes your application will fail and throw an exception. It's a good idea to show something useful to the user (See ExceptionAlert).

Maven Archetype

There is a Maven Archetype available that helps kickstarting your own project based on this code.

You might also like...

Allow runtime modification of JavaFX CSS

Allow runtime modification of JavaFX CSS

cssfx ⚠ WARNING ⚠ In version 11.3.0 we have relocated & refactored the project. maven groupId has been changed to fr.brouillard.oss java module name h

Jan 2, 2023

A JavaFX UI framework to create fully customized undecorated windows

A JavaFX UI framework to create fully customized undecorated windows

CustomStage A JavaFX undecorated stage which can fully be customized Donations If this project is helpful to you and love my work and feel like showin

Jan 6, 2023

MDI components for JavaFX

MDI components for JavaFX

DesktopPaneFX DesktopPaneFX is a JavaFX version of Swing’s JDesktopPane which can be used as a container for individual "child" similar to JInternalFr

Sep 23, 2022

Efficient VirtualFlow for JavaFX

Flowless Efficient VirtualFlow for JavaFX. VirtualFlow is a layout container that lays out cells in a vertical or horizontal flow. The main feature of

Nov 24, 2022

A framework for easily creating forms for a JavaFX UI.

A framework for easily creating forms for a JavaFX UI.

FormsFX Forms for business application made easy. Creating forms in Java has never been this easy! Maven To use this framework as part of your Maven b

Dec 30, 2022

:icecream: iOS frosty/translucent effect to JavaFX

:icecream: iOS frosty/translucent effect to JavaFX

FroXty is JavaFX library which replicates the famous iOS translucent effect with ease. Set-up FroXty can be imported into your project either by downl

Dec 11, 2022

💠 Undecorated JavaFX Scene with implemented move, resize, minimise, maximise, close and Windows Aero Snap controls.

💠 Undecorated JavaFX Scene with implemented move, resize, minimise, maximise, close and Windows Aero Snap controls.

Support me joining PI Network app with invitation code AlexKent FX-BorderlessScene ( Library ) 💠 Undecorated JavaFX Scene with implemented move, resi

Jan 4, 2023

Dynamic JavaFX form generation

FXForm 2 Stop coding forms: FXForm 2 can do it for you! About FXForm2 is a library providing automatic JavaFX form generation. How does it work? Write

Jan 9, 2023

A JavaFX library that allows Java2D code (Graphics2D) to be used to draw to a Canvas node.

A JavaFX library that allows Java2D code (Graphics2D) to be used to draw to a Canvas node.

FXGraphics2D Version 2.1, 3 October 2020. Overview FXGraphics2D is a free implementation of Java's Graphics2D API that targets the JavaFX Canvas. It m

Dec 31, 2022
Comments
  • Remove implementing Initalizable

    Remove implementing Initalizable

    It is implicitly marked as deprecated. Injecting the bundle and url is recommended to be done with @FXML annotation. And the FXMLLoader will call a no-arg initialize()

    https://docs.oracle.com/javase/8/javafx/api/javafx/fxml/Initializable.html

    I think the goal of this repo is awesome. 👍 JavaFX 🙂

    I can submit a PR if you are accepting external input.

    opened by pell-je 1
Owner
fuin.org
fuin.org
Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE 8 and provides the functionalities to use and handle easily Tiles in your JavaFX application.

Lib-Tile Intention Lib-Tile is a multi Maven project written in JavaFX and NetBeans IDE and provides the functionalities to use and handle easily Tile

Peter Rogge 13 Apr 13, 2022
Tray Icon implementation for JavaFX applications. Say goodbye to using AWT's SystemTray icon, instead use a JavaFX Tray Icon.

FXTrayIcon Library intended for use in JavaFX applications that makes adding a System Tray icon easier. The FXTrayIcon class handles all the messy AWT

Dustin Redmond 248 Dec 30, 2022
Example of using the TestFX library to perform E2E tests in a Maven project

demoTestFX Ejemplo de uso de la librería TestFX para realizar pruebas E2E en un proyecto Maven. El principal problema para conseguir ejecutar los test

null 1 Jan 28, 2022
A project that shows the different ways on how to create custom controls in JavaFX

JavaFX Custom Controls This project will show different ways on how to create custom controls in JavaFX. It will cover the following approaches: Resty

Gerrit Grunwald 27 Sep 5, 2022
The goal of this project is to create AssertJ assertions for JavaFX (8).

The goal of this project is to create AssertJ assertions for JavaFX (8).

Manuel Mauky 6 Jul 30, 2021
Collection of Binding helpers for JavaFX(8)

Advanced-Bindings for JavaFX (8) advanced-bindings is a collection of useful helpers and custom binding implementations to simplify the development of

Manuel Mauky 63 Nov 19, 2022
Docking framework for JavaFX platform

Docking framework for JavaFX platform AnchorFX is a gratis and open source library for JavaFX to create graphical interfaces with docking features Anc

Alessio Vinerbi 197 Oct 15, 2022
A library of +70 ready-to-use animations for JavaFX

AnimateFX A library of ready-to-use animations for JavaFX Features: Custom animations Custom interpolators Play/Stop animation Play an animation after

Loïc Sculier 366 Jan 5, 2023
BootstrapFX: Bootstrap for JavaFX

BootstrapFX BootstrapFX is a partial port of Twitter Bootstrap for JavaFX. It mainly provides a CSS stylesheet that closely resembles the original whi

Kordamp 810 Dec 28, 2022
A Java framework for creating sophisticated calendar views (JavaFX 8, 9, 10, and 11)

CalendarFX A Java framework for creating sophisticated calendar views based on JavaFX. A detailed developer manual can be found online: CalendarFX 8 D

DLSC Software & Consulting GmbH 660 Jan 6, 2023