Example usage for javafx.beans.property IntegerProperty addListener

List of usage examples for javafx.beans.property IntegerProperty addListener

Introduction

In this page you can find the example usage for javafx.beans.property IntegerProperty addListener.

Prototype

void addListener(ChangeListener<? super T> listener);

Source Link

Document

Adds a ChangeListener which will be notified whenever the value of the ObservableValue changes.

Usage

From source file:Main.java

public static void main(String[] args) {
    IntegerProperty counter = new SimpleIntegerProperty(100);

    // Add a change listener to the counter property
    counter.addListener(Main::changed);

    System.out.println("Before changing the counter value-1");
    counter.set(101);// w ww.j  a  v a 2 s  .  co m
    System.out.println("After changing the counter value-1");

    System.out.println();
    System.out.println("Before changing the counter value-2");
    counter.set(102);
    System.out.println("After changing the counter value-2");

    // Try setting the same value
    System.out.println();
    System.out.println("Before changing the counter value-3");
    counter.set(102); // No change event will be fired.
    System.out.println("After changing the counter value-3");

    // Try setting a different value
    System.out.println();
    System.out.println("Before changing the counter value-4");
    counter.set(103);
    System.out.println("After changing the counter value-4");
}

From source file:Main.java

public static void main(String[] args) {
    IntegerProperty intProperty = new SimpleIntegerProperty(1024);
    final ChangeListener changeListener = new ChangeListener() {
        @Override//from  w  w  w .jav a 2s  .  c  o  m
        public void changed(ObservableValue observableValue, Object oldValue, Object newValue) {
            System.out.println("oldValue:" + oldValue + ", newValue = " + newValue);
        }
    };

    intProperty.addListener(changeListener);
    intProperty.set(5120);

    intProperty.removeListener(changeListener);

    intProperty.set(6144);
}