mvvmFX 1.0.0

Some days ago we have released the first stable release of our mvvmFX library that helps you to implement the Model-View-ViewModel pattern with JavaFX.

The new release can be used with Maven/Gradle:

compile 'de.saxsys:mvvmfx:1.0.0'

Additionally Alex and me have written an article for This is a german version. An english version of the article will follow next week.


JUG-GR: Model-View-* - UI design patterns in detail

On december 3, 2014 I gave another talk at the Java-User-Group Görlitz with the title “Model-View-* : UI-Design-Patterns im Detail”.

The talk was all about the Model-View-Controller pattern and it’s variants like Model-View-Presenter (in different flavours) and Model-View-ViewModel. The example code was written in JavaFX. You can find the Code here on github. Of course I also presented the usage of our own MVVM framework mvvmFX.

Additionally I spoke about the scope of UI patterns: On the one hand side you can see “MVC” at the abstraction level of a single UI control. In the talk I used the example of a TextField control.

On the other hand you will often here people talking about “MVC” when they talk about the overall application architecture. I compared the terms of MVC with the well-known Three-tier Architecture and the less common CQRS architecture.


EasyDI Example

This tutorial will show you the usage of Easy-DI. All files for this example can be found in the github-project in the package /src/test/java/eu/lestard/easydi/examples/coffee

Let’s assume this class diagram for a coffee machine application:


In this class diagram we can see the dependencies of each class: The CoffeeMachine has a reference to the WaterTank and the CoffeePowderProvider. The CoffeePowderProvider has a reference to the BeanContainer and to the Mill.


Dependency Injection in less then 50 lines of code

I’m a big fan of the Dependency Injection design pattern and I’m using it a lot. I’m saying “design pattern” because when I’m thinking and talking about “DI” I don’t think about frameworks, big containers and a lot of magic. Instead, for me DI is a simple concept of how you write your classes and put them together.

In the past I’ve used many DI frameworks like Guice, CDI/Weld, EJB and Spring. In other use cases (for example my SnakeFX game) I’ve done the DI by hand:

Simply put all dependencies of a class into the constructor of this class. In the main method you can now start to instantiate the classes you need starting by the ones that have no dependencies and can therefore be instantiated without constructor parameters needed. It’s easy and this way you can’t create cyclic dependencies by accident. Look at an old version of the DependencyInjector class of SnakeFX to see what I mean.

Learning how to do the DI by hand was a real eye-opener for me. You can learn that DI is no magic at all and you will lose all your fear from the big buzzword “Dependency Injection”. It’s nothing special. Simply a design pattern.


New release of Advanced-Bindings

Last week I’ve released a new minor version of my Advanced-Bindings library. In this post I will describe the new features in more detail.

Logic Bindings

In the standard JavaFX Bindings API there are methods to create bindings for the logical OR and AND operations. The drawback of these methods is that they can only be used to combine exactly two observable boolean values.

In the new LogicBindings class there are now methods to create OR and AND bindings with a variable number of arguments.

ObservableBooleanValue a = ...
ObservableBooleanValue b = ...
ObservableBooleanValue c = ...
ObservableBooleanValue d = ...

BooleanBinding and = LogicBindings.and(a,b,c,d);

BooleanBinding or = LogicBindings.or(a,b,c,d);


Adjustable UI Brightness with JavaFX

Maybe some of you know or have already worked with Adobe products like Premier Pro or After Effects.

From the perspective of a UI developer there are many cool things about these products. For example you can seamlessly fade the brightness of the UI and it looks great in every brightness level (which seems to be a hard task).

This is cool because there are good reasons for users to prefer either a dark or light interface. For example some creative artists like to work in a dimmed office so that no light from outside is overlaying the colors picture/video they are working on. In this situation a dark user interface is better then a light one because it’s more comfortable for the eyes.

On the other hand I know people how prefer a light and friendly user interface because a dark one would give them a depressive fealing.

So it can be a big plus for the usability of your application when you allow the user to adjust the brightness of your app.

Adjustable Brightness in JavaFX

Something like this can be done with JavaFX too. With JavaFX 8 there was a new default stylesheet created known as modena.

In this stylesheet there is a color definition named -fx-base that is, as the name suggests, the base for all other color definitions in the stylesheet.

When you adjust the value of -fx-base all other colors will be adjusted automatically in relation to -fx-base.


The first thing to do is to create an IntegerProperty that will hold the brightness level in a range from 0 to 100%.

IntegerProperty brightness = new SimpleIntegerProperty();

After that we create a StringExpression (which is a base class of StringBinding) that contains the style definition of -fx-base with the value of our brightness property.

DoubleBinding colorValue = brightness.multiply(2.55);
StringExpression styleString = 
    Bindings.format("-fx-base:rgb(%1$.0f , %1$.0f, %1$.0f)", colorValue);

For this task we can use the Bindings.format method that takes a format string and an observable value. In the example I’m using the rgb css method to define the color. This method takes the color information for every channel in a range from 0 to 255. For that reason I’m creating a DoubleBinding that contains the multiplication of our brightness property (from 0 to 100) with 2.55 so that the value range is correct.

The last step is to bind the style property of the root container of your application to the StringExpression with our style definition.

Parent root = ...


This way the styling of the application is adjusted everytime the brightness property changes.

I’ve created a small example app that shows the usage of this binding. In the app I have bound the brightness property to a slider so you can change the brightness level without interruption. To demonstrate the effect I created a dummy form with some JavaFX controls.







You can find the example code on github: Feel free to use it in your own applications!


SchachZWO Online

In the lecture “XML based applications” at the HSZG we were working on a project called “SchachZWO Online”. “Schach” is the german word for “chess” and “ZWO” is another word for “two” so (as you can guess) this is a chess like online game.

SchachZWO (offline)

screenshot from the official website

The basic for the project is a board game that a game author from dresden has developed. In his “SchachZWO” you play on a 7x7 or 9x9 board with some special figures: Instead of the rook and the queen you have the “Mann” (man) and “Frau” (woman). Instead of the pawn you have the “Rocks” and instead of the king you have the “Zenit” (zenith). On the 9x9 board you have two additional figures with special movement capabilities: The “Wissen” (knowledge) and the “Glauben” (faith).

One of the main differences between chess and “SchachZWO” is that there are more than one possibilities to win the game. Beside the classical chess mate you win when you move your zenith to the middle field of the board. Only the zenith can step on this field in the middle, all other figures aren’t allowed to step on the field.

In the first place this rules might sound a little strange to you but it’s realy fun to play the game. At the moment the board game isn’t available for buying but it will be in the near future. Fisit the website of the game author when you like to know more:

SchachZWO Online


Our project for the lecture was to create an online multiplayer browser game version of this game. In the client we used HTML5 canvas together with JQuery to draw the board and the figures. To create a modern Single-Page-Application we used Angular.JS and Require.JS in the client.

On the server side we have a node.js together with express.js. There are REST like webservices where the client can GET the current state of the board and can POST new moves.

To tell the client that the opponent has done a move we use Server-Sent Events to send messages. The database connection was created in a generic manner to be able to replace the database implementation. At the moment we have a MongoDB and CouchDB implementation.

State of Play

The lecture is over and we finished the project. We have decided to put the source code on github: and you can play the game online at:

Please note that this was the first Node.JS project for all of us. We aren’t pros and we hadn’t had much time to finish this project so the source code will probably not be high quality. But of cause we always like to learn: When you have suggestions on what we can do better please tell us!

Also note that the game is sort of a prototype. We hadn’t had the time to do much quality assurance and testing so it’s best to see the hostet version as sort of a “BETA”. When you find bugs please report them on github:


Advanced-Bindings for JavaFX

I’m a big fan of JavaFX’s Properties and Data-Bindings. In my opinion, one of the most interesting part of the data binding capabilities of JavaFX is that you can create a binding that represents a calculation of values. For example you can create a binding that represents the addition of two integer properties:

import javafx.beans.binding.Bindings;
import static eu.lestard.assertj.javafx.api.Assertions.assertThat;

public void test(){
    IntegerProperty a = new SimpleIntegerProperty(12);
    IntegerProperty b = new SimpleIntegerProperty(30);

    NumberBinding c = Bindings.add(a, b);




There are binding method for basic operations like add, subtract, multiply, divide. But what if you need some more specific operations like exponentiation or sine?

To fill this gap I have created a library called “advanced-bindings” that will become a collection of custom bindings that are needed to create application logic with data bindings. The first step was to create binding implementations for all methods of java.lang.Math. This way you can do stuff like this:

public void testPow(){

    DoubleProperty a = new SimpleDoubleProperty(3);
    DoubleProperty b = new SimpleDoubleProperty(2);

    final DoubleBinding pow = MathBindings.pow(a, b);

    // 3^2 = 9


    // 5^3 = 125

In the future I will add more useful helpers and custom bindings. If you have ideas feel free to add an issue at github.

I have uploaded the library to [maven-central]( eu.lestard advanced-bindings 0.1.0 jar) so you can use it with Gradle:
compile 'eu.lestard:advanced-bindings:0.1.0'

or with Maven:



Again, I have rewritten one of my old games with JavaFX. This time I’ve created a JavaFX version of my old java swing game ColorPuzzle (yes I know, the name isn’t very creative).

screenshot of the game

The game mechanics are the same: You can switch the color of all fields under your control. Everytime you are switching the active color, all fields in the direct neighbourhood of your own fields with that same color are going under your control from now on. The goal is to bring all fields under your control with the fewest moves.

Before you ask: Yes, the game idea is not my invention, there are many games of this type out there and my version is only a clone. I create games only because programming is fun and not to become the best game inventor :-)

The code is available on github:

Grid Component

While the development of the game I have encapsulated the logic for manipulating and drawing the grid and extracted it into it’s own component. This way I was able to reuse the grid logic for other projects like SnakeFX.

You can view the code for this grid component on github too ( but it’s not intended for wide usage at the moment as documentation and testing far from production ready. It’s more like a playground for me.

In another post I will describe the idea behind the grid component in more detail.


Another reason to build the game was to create a simple example for our own UI framework MvvmFX.



As you probably already know I’m a big fan of the AssertJ library. That’s the reason I’ve done a talk about it at the JavaUserGroup Görlitz.

I like the way you can write readable unit tests and are supported by the IDE because AssertJ is implemented as a Fluent-API.

In the past weeks I’ve written a package of assertions specially for JavaFX. With this assertions you can verify the values of JavaFX Properties and Bindings.

With the normal AssertJ you would write something like this:

DoubleProperty x = new SimpleDoubleProperty(10.13);


With my extensions you don’t need to call the .get() all the time. Instead you can write:


Project Info

The project is hosted on github:

I’ve already uploaded it to maven central so you can use it with gradle:

testCompile 'eu.lestard:assertj-javafx:0.1.0'

or maven:


Tell me what you think. If you have ideas for new assertions that could be added feel free to add an issue in the issue tracker.