Bind value with javafx.beans.binding.* binding objects - Java JavaFX

Java examples for JavaFX:Bindable Properties

Description

Bind value with javafx.beans.binding.* binding objects

Demo Code

import javafx.beans.binding.NumberBinding;
import javafx.beans.property.IntegerProperty;
import javafx.beans.property.SimpleIntegerProperty;

public class Main {

  public static void main(String[] args) {
    System.out.println("A Area of a Rectangle [High level Fluent API]");

    // Area = width * height
    final IntegerProperty width = new SimpleIntegerProperty(10);
    final IntegerProperty height = new SimpleIntegerProperty(10);

    NumberBinding area = width.multiply(height);

    System.out.println("Current - Width and Height     : " + width.get() + " "
        + height.get());//  w  ww.  ja  v  a 2s.c o m
    System.out.println("Current - Area of the Rectangle: " + area.getValue());
    System.out.println("Modifying width and height");

    width.set(100);
    height.set(700);

    System.out.println("After - Width and Height     : " + width.get() + " "
        + height.get());
    System.out.println("After - Area of the Rectangle: " + area.getValue());

    System.out.println();
    System.out.println("A Volume of a Sphere [low level API]");
  }
}

Related Tutorials