/ DataFX / New Desktop Application Framework & DataFX

New Desktop Application Framework & DataFX

Hendrik on 2014/11/01 - 19:00 in DataFX, Desktop Application Framework (JSR 377), JavaFX

Maybe you have mentioned that Andres Almiray is planing a new desktop application framework JSR. I had a chat with him some days ago at the canoo hq and we discussed some points of this project. In addition Andres gave me an introduction to Griffon and I showed him DataFX 8.
One of the core features of the framework should be UI toolkit independency. By doing so the framework will only contain general definitions and JavaFX or Swing specific implementations will be loaded by SPI, for example.
Griffon already contains this abstraction but DataFX is hardly coded against JavaFX. I think this is absolutely ok and at the moment there eis no plan to support other UI toolkits that JavaFX with DataFX. As said the application framework will define general classes and interfaces and maybe DataFX will be one of the JavaFX implementation. We will see what happens in the future.

Generalizing the DataFX concepts

If DataFX should become an implementation of the JSR specification it must implement general interfaces and support a toolkit independent architecture. Therefore I did some tests and create a small platform independent framework based on DataFX architecture and APIs. I chose the concurrent API and the controller API of DataFX and created more general versions. As a benefit I created some cool code and features that will be integrated in DataFX 8.1. Let’s have a look at the framework that is called “JWrap”. You can find the sources at GitHub. Because this was only a test there isn’t any javadoc at the moment but the project contains a Swing and a JavaFX example. JWrap has zero dependencies and defines a MVC and a concurrency API. Both API are platform independent and you don’t need dependencies to Swing or JavaFX to use them.

JWrap concurrency utils

JWrap contains a UIToolkit class that can be used to work with the event and rendering thread of the underlying UI toolkit. Here are the methods that are defined in the class:

By using these methods you can interact with the event and rendering thread of the used UI toolkit. To do so you must configure JWrap. This can be done by only one line of code. Here is an example how you configure JWrap to use the Swing EDT:

There are several other concurrency classes in JWrap that all depend on the UIToolkit class. By doing so you can now use all the concurrency helpers in JWrap and automatically the EDT will be used as application thread. I ported the ProcessChain of DataFX to JWarp and now you can code the following in your Swing application:

I think this code is much better than using the SwingWorker. You can easily use the ProcessChain in any Swing application that supports Java 8.


DataFX contains the controller and flow API that can be used to define MVC based views in JavaFX. I ported some parts of this API to JWarp and created a UI toolkit independent way to define MVC based controllers. JWrap contains some annotations that can be used to create a link between the view and the controller of a dialog.
Let’s start with the swim example. As a first step we define the view and define names for all the UI components:

The second class of the dialog will be the controller class. In this class JWrap annotations can be sued to inject view components in the controller and define interaction:

The @ViewNode annotation can be compared to the @FXML annotation that is used in JavaFX and DataFX to inject view nodes that are defined in FXML in a controller. The @ViewNode annotation has some benefits because it can be used for FXML based view and for coded view (this is one of the features that I will integrate in DataFX 8.1).
The JavaFX version looks mainly the same. Here is the code for the view class:

And here we have the controller class:

As you can see the Swing controller class and the JavaFX controller looks mainly the same. Annotations like @ViewNode can be used in Swing and JavaFX.

The future of JWrap

I created this project to test of a UI independent API can look like. I don’t plan to continue working on the library. Maybe I will use it when checking some other ideas for the application framework JSR.
I think that the library can be a benefit for Swing developers. By using JWrap they will get some lambda based concurrency APIs and a MVC framework that can be used to structure the code or prepare a migration to JavaFX.


Send Us A Message Here

Your email address will not be published. Required fields are marked *

  • 2014/12/21

    Can’t you use CompletableFuture in place of ProcessChain and Executor interface as base for UIToolkit ?

    Marcin Wisnicki
  • 2014/12/22

    To expand what I had in mind:

    private void copy() {
    supplyAsync(() -> myTextField.getText()), UIToolkit.current()).
    thenApplyAsync(t -> WeatherService.getWeather(t)).
    thenAcceptAsync(t -> myLabel.setText(t), UIToolkit.current()).
    whenCompleteAsync((_,e) -> if (e != null) {
    }, UIToolkit.current());

    Marcin Wisnicki
    • 2014/12/24

      Hi Marcin,
      using the completableFuture is a good idea. I created the ProcessChain in DataFX before I knew about this new class. I think there will be a new and refactored version for the Desktop Application JSR. In this case the CompletableFuture will be used as a base.
      Thanks for the feedback

  • 2016/02/02

    Hi hendrik ,

    This my code detail ,

    I have one seperate fx view controller == >LoginFXController.java

    fx view file == > login_screen.fxml

    I just loaded this controller through fxmlloader class called ==>ConfigurationControllers.java

    I have done the same method binding and field injection as per the jwrap project.

    At the controller load time , a listener is registered for the button action.

    But after application loaded , whenever i clicked on the login button , contorl does’t goes to the registered listener.

    this is my problem .

    Baskaran Radhakrishnan
    • 2016/02/02

      How do you know that the listener is really registered? How do you register the listener?

      • 2016/02/03

        Actually in the MVCGroup.java class , there is one method called as “createActionBinding” , in that i can see it in the eclipse debugging mode , action-listener is registered for button for my LoginFxController.
        But at the time user clicked on that button, control is directly goes to the respected button action method.

        So this way i can assume that , listener is not invoking , actually I am very new to this kind of handler and listener functionality .

        So can you help me.

        Baskaran Radhakrishnan
      • 2016/02/03

        Can you give me one example project for event-listners and handlers like same jwrap for javafx with fxml.

        Baskaran Radhakrishnan
        • 2016/02/03

          So most easy case is to inject a button that is defined in FXML by using the @FXML annotation in your controller class. By doing so you can define a listener in the init() method of the controller:
          myButton.setOnAction(e -> myActionMethod());

          Is this working for you? I think this is the basic

          • 2016/02/03

            Ya we can do like that , but this static kind of coding , actually i have already code it like that.
            But at the time of loading the view controller , i want to register the event listener on the fly.
            Whenever button present in the view , i should register a listener for that button action.
            In the Jwrap project you have done it in the same way .

            Baskaran Radhakrishnan
          • 2016/02/03

            Ok, just wanted to check this 🙂
            As far as I understand now you don’t want to use JWrap but understand how the listeners are managed internally, right?

  • 2016/02/04

    S Hendrik ,

    Can you help me ?

    I want to implement dynamic event listener and handler for javafx with fxml based application.

    I want to use jwrap with fxml based version.

    Can you get my point ?

    Baskaran Radhakrishnan