Advanced-Bindings for JavaFX

| tagged as

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 so you can use it with Gradle:

compile 'eu.lestard:advanced-bindings:0.1.0'

or with Maven: