Open jiasheng59 opened 1 year ago
You can try to:
The downside of this approach is that you have to know the index of the T you are going to update.
T oldT = list.get(index);
T newT = copy(oldT);
// modify newT
list.set(index, newT);
If you don't want to create new object, you may try:
T t = list.get(index);
// modify t
list.set(t);
Although I haven't tested this approach yet.
Yes, I think this could be the only approach. What I tried before is to make the attribute of T to be an ObservableValue / Property
, e.g. SimpleIntegerProperty
and see whether the change to the attribute will cascade to the list. But the GUI doesn't reflect the change automatically, but only changes when I explicitly click on the cell. (It's a bit strange)
Even when I use FilteredList
, and set a trivial Predicate
like p -> true
to it, the GUI still doesn't reflect the change automatically.
So what I did in the end is to remove and add as what @VietAnh1010 suggested. Does anyone have any idea on this matter?
Is it correct saying that
ObservableList
won't be able to detect changes inT
itself? Instead the list will only get notified when there's change to the list itself (as compared to the change of internal attribute ofT
). If it's the case, what if we want to detect changes to the attribute ofT
, meanwhile also detect the change to the entire list, will the change to the internal attribute ofT
cascade to theObservableList
wrapping around it?