Example usage for javafx.beans.binding ObjectBinding addListener

List of usage examples for javafx.beans.binding ObjectBinding addListener

Introduction

In this page you can find the example usage for javafx.beans.binding ObjectBinding addListener.

Prototype

@Override
    public void addListener(ChangeListener<? super T> listener) 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    ObjectProperty<Lighting> root = new SimpleObjectProperty<Lighting>();
    final ObjectBinding<Color> colorBinding = Bindings.select(root, "light", "color");
    colorBinding.addListener(new ChangeListener<Color>() {
        @Override/*  w  w  w  . java 2  s.  co m*/
        public void changed(ObservableValue<? extends Color> observableValue, Color oldValue, Color newValue) {
            System.out.println(oldValue + "new = " + newValue);
        }
    });
    Light firstLight = new Light.Point();
    firstLight.setColor(Color.BLACK);

    Light secondLight = new Light.Point();
    secondLight.setColor(Color.WHITE);

    Lighting firstLighting = new Lighting();
    firstLighting.setLight(firstLight);

    root.set(firstLighting);
    firstLighting.setLight(firstLight);
    firstLight.setColor(Color.RED);
}