thiloilg
thiloilg

Reputation: 2183

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?

Upvotes: 0

Views: 83

Answers (1)

fabian
fabian

Reputation: 82491

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.

Upvotes: 3

Related Questions