Say I have a JavaFX app with an observable class SomeObservableClass
with some Properties:
public class SomeObservableClass{
private StringProperty prop1 = new SimpleStringProperty();
private DoubleProperty prop2 = new SimpleDoubleProperty();
... constructors, getters and setters
}
and another class which has a property:
public class ParentClass{
private ObservableList<SomeObservableClass> sOC = FXCollections.observableArrayList();`
}
In this parent class I add a listener for the observable list: `
public class ParentClass{
private ObservableList<SomeObservableClass> observableList = FXCollections.observableArrayList();
public`ParentClass(List<SomeObservableClass> list){
this.observableList.addAll(list);
this.observableList.addListener((InvalidationListener) observable -> System.out.println("listener detected a change!"));`.
}
}
Now say that in a controller class I change the property of one of the SomeObservableClass objects:
public class Controller(){
private ParentClass parentClass;
public void changeSomeProps(){
SomeObservableClass anObservableObject = parentClass.getObservableList().get(0);
anObservableObject.setProp1("newVal");
}
}
This doesn't fire the listener. Why ?
I suspect I am lacking some code to make the listener aware that it should fire when any property of the list objects get modified, but I have no idea how to do that.