Java Reference
In-Depth Information
When we run the program in Listing 7-4, the following output is printed to the console:
Calling add("First"):
set = [First]
Change event data:
Was added: true
Was removed: false
Element added: First
Element removed: null
Calling addAll(Arrays.asList("Second", "Third")):
set = [Second, First]
Change event data:
Was added: true
Was removed: false
Element added: Second
Element removed: null
set = [Second, First, Third]
Change event data:
Was added: true
Was removed: false
Element added: Third
Element removed: null
Calling remove("Third"):
set = [Second, First]
Change event data:
Was added: false
Was removed: true
Element added: null
Element removed: Third
In the preceding example, notice that the
addAll()
call generated two set change events because the list that was
added to the observable set contains two elements.
Understanding
ObservableArrays
The
ObservableArray
interface is introduced for situations where a list of primitive int or float values needs
to be observed but the overhead of boxing and unboxing of the primitive values every time they are added or
removed from the list is unacceptable for performance reasons. Implementations of
ObservableArray
and its two
subinterfaces,
ObservableIntegerArray
and
ObservableFloatArray
, are expected to use primitive arrays as the
backing stores of their content. The JavaFX 3D API makes use of
ObservableArray
,
ObservableIntegerArray
, and
ObservableFloatArray
. Figure
7-4
is a UML diagram showing the
ObservableArray
and supporting interfaces.
Search WWH ::
Custom Search