javax.swing
public class SpinnerListModel extends AbstractSpinnerModel implements Serializable
SpinnerModel
which uses the values
contained within a list or an array. The backing list or array is
only stored as a reference within the class. As a result, changes
made elsewhere to the members of the list or array are reflected by
this model.
The model itself inherits a list of ChangeListener
s from
AbstractSpinnerModel
. As this code is unaware of changes
made to the backing list or array, it is the responsibility of the
application using the model to invoke fireStateChanged()
,
in order to notify any ChangeListener
s, when the list or array
changes. The model handles notification when the reference itself
is changed via setList()
or when the current value is
set directly using setValue()
.
Since: 1.4
See Also: SpinnerModel AbstractSpinnerModel JSpinner
Constructor Summary | |
---|---|
SpinnerListModel()
Constructs a default SpinnerListModel . | |
SpinnerListModel(List<?> list)
Constructs a SpinnerListModel using the supplied list.
| |
SpinnerListModel(Object[] array)
Constructs a SpinnerListModel using the supplied array.
|
Method Summary | |
---|---|
List<?> | getList()
Returns the backing list for this model.
|
Object | getNextValue()
Returns the next value from the list, which is the same as the element
stored at the current index + 1. |
Object | getPreviousValue()
Returns the previous value from the list, which is the same as the element
stored at the current index - 1. |
Object | getValue()
Returns the current value of the model. |
void | setList(List<?> list)
Changes the backing list for this model. |
void | setValue(Object value)
Sets the current value of the model to be the one supplied.
|
SpinnerListModel
. This
is a model backed by a list containing only the single
String
element, "empty".SpinnerListModel
using the supplied list.
The model maintains a reference to this list, and returns
consecutive elements in response to calls to getNextValue()
.
The initial value is that at position 0, so an initial call
to getValue()
returns the same as list.get(0)
.
Parameters: list The list to use for this model.
Throws: IllegalArgumentException if the list is null or contains no elements.
See Also: getNextValue getValue
SpinnerListModel
using the supplied array.
The model stores a reference to the wrapper list returned by
Arrays.asList()
. The wrapper list reflects modifications
in the underlying array, so these changes will also be reflected
by the model. The model produces consecutive elements from the array
in response to calls to getNextValue()
. The initial
value returned by getValue()
is the same as
array[0]
.
Parameters: array The array to use for this model.
Throws: IllegalArgumentException if the array is null or contains no elements.
See Also: (Object[])
getNextValue getValue
Returns: The backing list.
Returns: The next value from the list or null.
Returns: The previous value from the list or null.
getNextValue()
or getPreviousValue()
.
Returns: The current value.
See Also: getPreviousValue getNextValue
ChangeEvent
is fired if the list being used actually
changes (i.e. the new list is not referentially equal (!=) to the
old one).
Parameters: list The new list to use.
Throws: IllegalArgumentException if the list is null or contains no elements.
See Also: ChangeEvent
getNextValue()
and
getPreviousValue()
return the objects following
and prior to the supplied value, respectively.
Parameters: value The requested new value of the list.
Throws: IllegalArgumentException if the supplied value does not exist in the backing list.
See Also: getPreviousValue getNextValue