Java Reference
In-Depth Information
When we run the program in Listing 7-1, the following output is printed to the console:
Calling add("First"):
list invalidated
strings = [First]
Calling add(0, "Zeroth"):
list invalidated
strings = [Zeroth, First]
Calling addAll("Second", "Third"):
list invalidated
strings = [Zeroth, First, Second, Third]
Calling set(1, "New First"):
list invalidated
strings = [Zeroth, New First, Second, Third]
Calling addAll(3, list):
list invalidated
strings = [Zeroth, New First, Second, Second_1, Second_2, Third]
Calling remove(2, 4):
list invalidated
strings = [Zeroth, New First, Second_2, Third]
Calling remove() on iterator:
list invalidated
strings = [New First, Second_2, Third]
Calling remove() on iterator:
list invalidated
strings = [Second_2, Third]
Calling removeAll("Third", "Fourth"):
list invalidated
strings = [Second_2]
Indeed, every call that we made in the code to change the content of the observable list triggered a callback on
both the invalidation listener and the list change listener.
If an instance of an invalidation listener or a list change listener has already been added as a listener to an
observable list, all subsequent addListener() calls with that instance as an argument are ignored. Of course, you can
add as many distinct invalidation listeners and list change listeners as you like to an observable list.
Handling Change Events in ListChangeListener
In this section, we take a closer look at the ListChangeListener.Change class and discuss how the onChange()
callback method should handle the list change event.
As we saw in the preceding section, for an ObservableList obtained by calling FXCollections.
observableArrayList() , each mutator call—that is, each call to a single method that changes the content of the
observable list—generates a list change event delivered to each registered observer. The event object, an instance of
a class that implements the ListChangeListener.Change interface, can be thought of as representing one or more
discrete changes, each of which is of one of four kinds: elements added, elements removed, elements replaced, or
elements permuted. The ListChangeListener.Change class provides the following methods that allow you to get at
this detailed information about the change:
boolean next()
void reset()
 
Search WWH ::




Custom Search