I really have difficulties to understand how the ObservableList
object is working in JavaFX. I want to monitor if an object in the List
has been modified. So far, I only see that I can monitor if the List
, as an entity itself, has been modified... but not the objects within the List
:
ObservableList<Stuff> myList = FXCollections.<Stuff>observableArrayList();
myList.add(someStuff);
myList.addListener((ListChangeListener.Change<? extends Stuff> change) -> {
while(change.next()){
if(change.wasUpdated()){
System.out.println("Update detected");
}
else if(change.wasPermutated()){
}
else{
for (Stuff remitem : change.getRemoved()) {
//do things
}
for (Stuff additem : change.getAddedSubList()) {
//do things
}
}
}
});
someStuff.setThing("clobber"); // trigger listener
Is there a way to do this? I'm looking for a workflow such that a modification to the object triggers → modification on the list → refresh on a some view.
Thanks
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…