Interface ObservableArray<T extends ObservableArray<T>>
- Type Parameters:
T
- actual array instance type
- All Superinterfaces:
Observable
- All Known Subinterfaces:
ObservableFaceArray
,ObservableFloatArray
,ObservableIntegerArray
- All Known Implementing Classes:
ObservableArrayBase
ObservableArray
is an array that allows listeners to track changes
when they occur. In order to track changes, the internal array
is encapsulated and there is no direct access available from the outside.
Bulk operations are supported but they always do a copy of the data range.
You can find them in subclasses as they deal with primitive arrays directly.
Implementations have both capacity
, which is internal array length,
and size
. If size needs to be increased beyond capacity, the capacity
increases to match that new size. Use trimToSize()
method
to shrink it.
- Since:
- JavaFX 8.0
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(ArrayChangeListener<T> listener) Add a listener to this observable array.void
clear()
Empties the array by resizing it to 0.void
ensureCapacity
(int capacity) Grows the capacity of this array if the current capacity is less than givencapacity
, does nothing if it already exceeds thecapacity
.void
removeListener
(ArrayChangeListener<T> listener) Tries to remove a listener from this observable array.void
resize
(int size) Sets new length of data in this array.int
size()
Retrieves length of data in this array.void
Shrinks the capacity to the current size of data in the array.Methods declared in interface javafx.beans.Observable
addListener, removeListener, subscribe
-
Method Details
-
addListener
Add a listener to this observable array.- Parameters:
listener
- the listener for listening to the array changes- Throws:
NullPointerException
- iflistener
isnull
-
removeListener
Tries to remove a listener from this observable array. If the listener is not attached to this array, nothing happens.- Parameters:
listener
- a listener to remove- Throws:
NullPointerException
- iflistener
isnull
-
resize
void resize(int size) Sets new length of data in this array. This method grows capacity if necessary but never shrinks it. Resulting array will contain existing data for indexes that are less than the current size and zeroes for indexes that are greater than the current size.- Parameters:
size
- new length of data in this array- Throws:
NegativeArraySizeException
- if size is negative
-
ensureCapacity
void ensureCapacity(int capacity) Grows the capacity of this array if the current capacity is less than givencapacity
, does nothing if it already exceeds thecapacity
.- Parameters:
capacity
- the capacity of this array
-
trimToSize
void trimToSize()Shrinks the capacity to the current size of data in the array. -
clear
void clear()Empties the array by resizing it to 0. Capacity is not changed.- See Also:
-
size
int size()Retrieves length of data in this array.- Returns:
- length of data in this array
-