Interface ObservableArray<T extends ObservableArray<T>>
Type Parameters:
T - actual array instance type
All Superinterfaces:
All Known Subinterfaces:
ObservableFaceArray, ObservableFloatArray, ObservableIntegerArray
All Known Implementing Classes:
public interface ObservableArray<T extends ObservableArray<T>> extends Observable
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
All MethodsInstance MethodsAbstract Methods Modifier and Type Method and Description voidaddListener(ArrayChangeListener<T> listener)Add a listener to this observable array.voidclear()Empties the array by resizing it to 0.voidensureCapacity(int capacity)Grows the capacity of this array if the current capacity is less than givencapacity, does nothing if it already exceeds thecapacity.voidremoveListener(ArrayChangeListener<T> listener)Tries to remove a listener from this observable array.voidresize(int size)Sets new length of data in this array.intsize()Retrieves length of data in this array.voidtrimToSize()Shrinks the capacity to the current size of data in the array.-
Methods inherited from interface javafx.beans.Observable
addListener, removeListener
-
-
Method Detail
-
addListener
void addListener(ArrayChangeListener<T> listener)
Add a listener to this observable array.Parameters:
listener- the listener for listening to the array changesThrows:
NullPointerException- iflistenerisnull
-
removeListener
void removeListener(ArrayChangeListener<T> listener)
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 removeThrows:
NullPointerException- iflistenerisnull
-
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 arrayThrows:
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-
-
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
-
© 2008, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from JavaFX API Documentation.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Java, JavaFX and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.