Example usage for javafx.beans.value ChangeListener ChangeListener

List of usage examples for javafx.beans.value ChangeListener ChangeListener

Introduction

In this page you can find the example usage for javafx.beans.value ChangeListener ChangeListener.

Prototype

ChangeListener

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    IntegerProperty intProperty = new SimpleIntegerProperty(1024);
    final ChangeListener changeListener = new ChangeListener() {
        @Override//from  w  ww . jav  a  2s . co 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);
}

From source file:Main.java

public static void main(String[] args) {
    SimpleIntegerProperty xProperty = new SimpleIntegerProperty(0);

    // Adding a change listener with anonymous inner class
    xProperty.addListener(new ChangeListener<Number>() {
        @Override/*from w w  w  .j  a v a2  s  .c  o  m*/
        public void changed(ObservableValue<? extends Number> ov, Number oldVal, Number newVal) {
            System.out.println("old value:" + oldVal);
            System.out.println("new value:" + newVal);
        }
    });

    // Adding a change listener with lambda expression
    xProperty.addListener((ObservableValue<? extends Number> ov, Number oldVal, Number newVal) -> {
        System.out.println("old value:" + oldVal);
        System.out.println("new value:" + newVal);
    });
}

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//from w w w . j  ava 2s.  c  o  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);
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(300);//  w  w w. j  a  v  a2 s .  com
    stage.setHeight(150);
    final CheckBox cb = new CheckBox();
    cb.setText("checkBox");

    cb.selectedProperty().addListener(new ChangeListener<Boolean>() {
        public void changed(ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) {
            System.out.println(cb.isSelected());
        }
    });
    ((Group) scene.getRoot()).getChildren().add(cb);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(300);//from   w  ww  . j a  v a  2 s  .  c  om
    stage.setHeight(150);
    final CheckBox cb = new CheckBox();
    cb.setText("checkBox");
    cb.setSelected(true);

    cb.selectedProperty().addListener(new ChangeListener<Boolean>() {
        public void changed(ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) {
            System.out.println(cb.isSelected());
        }
    });
    ((Group) scene.getRoot()).getChildren().add(cb);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(300);//w  w w. j  a v a2 s  .c  o  m
    stage.setHeight(150);
    final CheckBox cb = new CheckBox();
    cb.setText("checkBox");
    cb.setAllowIndeterminate(true);

    cb.selectedProperty().addListener(new ChangeListener<Boolean>() {
        public void changed(ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) {
            System.out.println(cb.isSelected());
        }
    });
    ((Group) scene.getRoot()).getChildren().add(cb);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(300);//from   w  w  w  .j a  v  a2 s .c o m
    stage.setHeight(150);
    final CheckBox cb = new CheckBox();
    cb.setText("checkBox");
    cb.setAllowIndeterminate(true);

    cb.selectedProperty().addListener(new ChangeListener<Boolean>() {
        public void changed(ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) {
            System.out.println(cb.isSelected());
            System.out.println(cb.isIndeterminate());
        }
    });
    ((Group) scene.getRoot()).getChildren().add(cb);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(300);/*  ww  w.ja va 2 s.co m*/
    stage.setHeight(150);
    final CheckBox cb = new CheckBox();
    cb.setText("checkBox");
    cb.setAllowIndeterminate(true);

    cb.selectedProperty().addListener(new ChangeListener<Boolean>() {
        public void changed(ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) {
            System.out.println(cb.isSelected());
            System.out.println(cb.isAllowIndeterminate());
        }
    });
    ((Group) scene.getRoot()).getChildren().add(cb);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(300);//from w  ww.  j  a  v  a2 s.co m
    stage.setHeight(150);
    final CheckBox cb = new CheckBox();
    cb.setText("checkBox");
    cb.setAllowIndeterminate(true);

    cb.indeterminateProperty().addListener(new ChangeListener<Boolean>() {
        public void changed(ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) {
            System.out.println(cb.isSelected());
        }
    });
    ((Group) scene.getRoot()).getChildren().add(cb);

    stage.setScene(scene);
    stage.show();
}

From source file:Main.java

@Override
public void start(Stage stage) {
    Scene scene = new Scene(new Group());
    stage.setWidth(300);/*from  w  w  w.  j a  v a 2  s .c o  m*/
    stage.setHeight(150);
    final CheckBox cb = new CheckBox();
    cb.setText("checkBox");
    cb.setAllowIndeterminate(true);

    cb.allowIndeterminateProperty().addListener(new ChangeListener<Boolean>() {
        public void changed(ObservableValue<? extends Boolean> ov, Boolean old_val, Boolean new_val) {
            System.out.println(cb.isSelected());
            System.out.println(cb.isIndeterminate());
        }
    });
    ((Group) scene.getRoot()).getChildren().add(cb);

    stage.setScene(scene);
    stage.show();
}