Java: Swing: JList and ListModel: ListModel
See also: Observable lists
Unfortunately there is no clear statement in the specification what exactly may have changed.
First of all it is used for the both cases: a) the item (i.e. the reference) was changed b) some property of the item changed that might concern the appearance.
Problem: In general you cannot not what property of the items might be of interest for the current ListCellRenderer, so you basically have to fire this event if any property changed for a general-purpose ListModel.
In the following text, "changed" means one of these things.
One problem is that generally I would say, if case a) happened, the item should be deselected if it was, since it is not the same anymore, while in case b) it should not. As JList cannot possibly distinguish between the events (without caching the whole ListModel's contents), the item always remains selected.
I distinguish between the following types of changes:
An interval of the ListModel has changed, but the size has remained the same.
The ListModel has totally new items (possibly with changed size). In theory this can be done by first firing intervalRemoved(0, oldSize - 1), and then intervalAdded(0, newSize - 1), but this requires that between these two calls the ListModel is in fact empty (otherwise the intervalRemoved event would have lied), which requires probably hacky code. If the size has changed in such a case, I suggest to fire the event with (0, max(oldSize, newSize) - 1), which is within the bounds allowed by the specification.
The ListModel is in fact a ComboBoxModel and the selected item has changed. Then the changed interval will be (-1, -1). This actually is an
incompatible (and undocumented) extension of the ListModel interface. ListDataListeners aren't required to expect events with negative indices.
(C) 2001-2009 Christian Kaufhold (swing@chka.de)