JavaFX SortedList: listen the list changes and the list items updated event

﹥>﹥吖頭↗ 提交于 2019-12-02 05:57:16
James_D

The SortedList observes its underlying ObservableList. Thus it will only update its order if the underlying list fires change events.

For an observable list to fire update events when the state of one of its elements changes (as opposed to the list adding, removing, or reordering elements), it must be observing the corresponding properties. This won't happen unless you tell it to do so, using an extractor. The extractor is a function which maps an element in the list to an array of properties that should be observed: if those properties change the list will fire update events. In your scenario, where the list is the underlying list for a sorted list, this will allow the sorted list to reorder itself.

So you need to create your underlying list as

final ObservableList<IntegerProperty> il =
   FXCollections.observableArrayList(
      ( IntegerProperty intProp ) -> new Observable[]{ intProp });

(ie. the property you want to observe is the element itself).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!