-
Notifications
You must be signed in to change notification settings - Fork 92
/
PropertyExample.java
44 lines (33 loc) · 1.51 KB
/
PropertyExample.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.jenkov.javafx.properties;
import javafx.application.Application;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.stage.Stage;
public class PropertyExample extends Application {
public static void main(String[] args) {
launch(args);
}
public void start(Stage primaryStage) {
Pane pane = new Pane();
ReadOnlyDoubleProperty widthProperty = pane.widthProperty();
widthProperty.addListener( new ChangeListener<Number> (){
@Override
public void changed(ObservableValue<? extends Number> observableValue, Number oldVal, Number newVal) {
System.out.println("widthProperty changed from " + oldVal.doubleValue() + " to " + newVal.doubleValue());
}
});
DoubleProperty prefWidthProperty = pane.prefWidthProperty();
prefWidthProperty.addListener( (ObservableValue<? extends Number> prop, Number oldVal, Number newVal) -> {
System.out.println("prefWidthProperty changed from " + oldVal.doubleValue() + " to " + newVal.doubleValue());
});
prefWidthProperty.set(123);
Scene scene = new Scene(pane, 1024, 800, true);
primaryStage.setScene(scene);
primaryStage.setTitle("2D Example");
primaryStage.show();
}
}