I have some code which I don't understand the result :
ObservableList<Integer> li = FXCollections.observableArrayList();
li.add(1);
li.add(2);
IntegerProperty intProp = new SimpleIntegerProperty(5);
li.add(intProp.getValue());
li.add(li.get(0) + li.get(2));
System.out.println(li);
li.addListener((ListChangeListener<Integer>) change -> {
li.set(3, li.get(0) + li.get(2));
});
intProp.setValue(3);
System.out.println(intProp.get());
System.out.println(li.get(2));
System.out.println(li);
I don't understand why the changing value of intProp doesn't affect affect the observableList, I mean the int in the position 2 should be the value of the property so the second and third sysout must me the same, and the first must be different from the last, but it isn't the case, and it gives me :
[1, 2, 5, 6]
3
5
[1, 2, 5, 6]
I tried to do some changes by writing this :
ObservableList<Integer> li = FXCollections.observableArrayList();
li.add(1);
li.add(2);
li.add(5);
li.add(li.get(0) + li.get(2));
System.out.println(li);
li.addListener((ListChangeListener<Integer>) change -> {
li.set(3, li.get(0) + li.get(2));
});
li.set(2, 3);
System.out.println(li);
it apparently works, but it gives me many errors which I don't understand.
Thanks !