it seems I have encountered a problem with ListProperties
. ObservableLists
implement the marker interface SortableList
that allows them to be sorted efficiently, firing only a single event. ListProperties
do not implement this interface (how could they...?). Instead they use the default implementation of the List
interface, firing a lot of changes.
The only solution I can see would be to call sort()
on the underlying List
directly. But this collides with the scheme of returning the Property
itself:
public ObservableList getSomeList()
{
return someListProperty();
}
which ensures that ListChangeListener
remain registered when the underlying List
is exchanged.
I would be happy to get some input, maybe I missed something?
I guess the
SortableList
you refer to is the one used inFXCollections.sort
.ListProperty
could implement theSortableList
interface.It may indeed be a good idea, since this would allow you to choose the way the wrapped list is sorted, if e.g.
FXCollections.sort
is used on the property. You could useFXCollections.sort
on the contained list in this case.How could they? Like this:
The only problem is, that
SortableList
is inside thecom.sun.javafx.collections
package (see It is a bad practice to use Sun's proprietary Java classes?).About your collision with the property scheme: there is none, if you define the property the intended way, see Using JavaFX Properties and Binding section Understanding Properties
The property would be implemented like this:
The
ListProperty
has to ensure theListChangeListener
s registered to it receive the change events from the wrapped list.Maybe you got confused with readonly list properties used in fxml, but a
ListProperty
is not readonly.You could still use this property in a fxml file, but you'd need to use a value of type
ObservableList
: