Search code examples
javajavafxpropertiesrelationexponential

How can I bind two SimpleDoubleProperty`s to each other with an exponential relation? JavaFX


I know how to do a binding like this:

doublePropertyOne.bind(doublePropertyTwo.multiply(2));

What I need is the example above with an exponential relation:

doublePropertyOne.bind(doublePropertyTwo.asExponentialOfE());

So that i get an doubleProperty which equals E^doubleProperty. Is there any way to accomplish this relation or how else would you implement it?


Solution

  • You can use the Bindings class to crate a binding that depends on doublePropertyTwo:

    doublePropertyOne.bind(Bindings.createDoubleBinding(() -> Math.exp(doublePropertyTwo.get()), doublePropertyTwo));
    

    Here the Callable passed as first parameter to createDoubleBinding is reevaluated every time the dependencies passed starting with the second parameter (in this case doublePropertyTwo) change.