Interface ObservableList<E>
- Type Parameters:
E- the list element type
- All Superinterfaces:
Collection<E>, Iterable<E>, List<E>, Observable, SequencedCollection<E>
- All Known Subinterfaces:
ObservableListValue<E>, WritableListValue<E>
- All Known Implementing Classes:
FilteredList, ListBinding, ListExpression, ListProperty, ListPropertyBase, ModifiableObservableListBase, ObservableListBase, ReadOnlyListProperty, ReadOnlyListPropertyBase, ReadOnlyListWrapper, SimpleListProperty, SortedList, TransformationList
A list that allows listeners to track changes when they occur. Implementations can be created using methods in
FXCollections
such as observableArrayList, or with a
SimpleListProperty.- Since:
- JavaFX 2.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionbooleanA convenience method for var-arg addition of elements.voidaddListener(ListChangeListener<? super E> listener) Add a listener to this observable list.default FilteredList<E> Creates aFilteredListwrapper of this list using the specified predicate.voidremove(int from, int to) A simplified way of callingsublist(from, to).clear().booleanA convenience method for var-arg usage of theremoveAllmethod.voidremoveListener(ListChangeListener<? super E> listener) Tries to remove a listener from this observable list.default booleanreplaceRange(int from, int to, Collection<? extends E> col) Replaces the elements in the range[from, to)with the elements from the given collection.booleanA convenience method for var-arg usage of theretainAllmethod.booleanClears the ObservableList and adds all the elements passed as var-args.booleansetAll(Collection<? extends E> col) Clears the ObservableList and adds all elements from the collection.default SortedList<E> sorted()Creates aSortedListwrapper of this list with the natural ordering.default SortedList<E> sorted(Comparator<E> comparator) Creates aSortedListwrapper of this list using the specified comparator.Methods declared in interface Collection
parallelStream, removeIf, stream, toArrayMethods declared in interface List
add, add, addAll, addAll, addFirst, addLast, clear, contains, containsAll, equals, get, getFirst, getLast, hashCode, indexOf, isEmpty, iterator, lastIndexOf, listIterator, listIterator, remove, remove, removeAll, removeFirst, removeLast, replaceAll, retainAll, reversed, set, size, sort, spliterator, subList, toArray, toArrayMethods declared in interface Observable
addListener, removeListener, subscribe
-
Method Details
-
addListener
Add a listener to this observable list.- Parameters:
listener- the listener for listening to the list changes
-
removeListener
Tries to remove a listener from this observable list. If the listener is not attached to this list, nothing happens.- Parameters:
listener- a listener to remove
-
addAll
A convenience method for var-arg addition of elements.- Parameters:
elements- the elements to add- Returns:
- true (as specified by Collection.add(E))
-
setAll
Clears the ObservableList and adds all the elements passed as var-args.- Parameters:
elements- the elements to set- Returns:
- true (as specified by Collection.add(E))
- Throws:
NullPointerException- if the specified arguments contain one or more null elements
-
setAll
Clears the ObservableList and adds all elements from the collection.- Parameters:
col- the collection with elements that will be added to this observableArrayList- Returns:
- true (as specified by Collection.add(E))
- Throws:
NullPointerException- if the specified collection contains one or more null elements
-
replaceRange
Replaces the elements in the range[from, to)with the elements from the given collection. The existing elements in the specified range are removed, and the new elements are inserted at positionfrom.If
from == to, the range is empty and the elements from the given collection are inserted at positionfrom.- Parameters:
from- start of the range (inclusive), must be in0..size()to- end of the range (exclusive), must be infrom..size()col- collection containing elements to be inserted, cannot benull- Returns:
trueif this list changed as a result of the call- Throws:
ClassCastException- if the class of an element of the specified collection prevents it from being added to this listNullPointerException- if the specified collection contains one or more null elements and this list does not permit null elements, or if the specified collection is nullIllegalArgumentException- if some property of an element of the specified collection prevents it from being added to this listIndexOutOfBoundsException- iffrom < 0,to > size(), orfrom > to- Since:
- 26
-
removeAll
-
retainAll
-
remove
void remove(int from, int to) A simplified way of callingsublist(from, to).clear(). As this is a common operation, ObservableList has this method for convenient usage.- Parameters:
from- the start of the range to remove (inclusive)to- the end of the range to remove (exclusive)- Throws:
IndexOutOfBoundsException- if an illegal range is provided
-
filtered
Creates aFilteredListwrapper of this list using the specified predicate.- Parameters:
predicate- the predicate to use- Returns:
- new
FilteredList - Since:
- JavaFX 8.0
-
sorted
Creates aSortedListwrapper of this list using the specified comparator.- Parameters:
comparator- the comparator to use or null for unordered List- Returns:
- new
SortedList - Since:
- JavaFX 8.0
-
sorted
Creates aSortedListwrapper of this list with the natural ordering.- Returns:
- new
SortedList - Since:
- JavaFX 8.0
-