JavaFX How to - Output binding Property with format








Question

We would like to know how to output binding Property with format.

Answer

/*ww  w.  ja  va 2s.com*/
import javafx.beans.binding.Bindings;
import javafx.beans.binding.NumberBinding;
import javafx.beans.binding.StringExpression;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;

public class Main {
  public static void main(String[] args) {
    IntegerProperty x1 = new SimpleIntegerProperty(0);
    IntegerProperty y1 = new SimpleIntegerProperty(0);

    final NumberBinding area = x1.multiply(y1).divide(2.0D);

    StringExpression output = Bindings.format(
        "For A(%d,%d), the area is %3.1f", x1, y1, area);

    x1.set(0);
    y1.set(0);

    System.out.println(output.get());

    x1.set(10);
    y1.set(110);

    System.out.println(output.get());
  }
}