java.lang.Object
javax.swing.AbstractSpinnerModel
javax.swing.SpinnerListModel
- All Implemented Interfaces:
Serializable
,SpinnerModel
A simple implementation of
SpinnerModel
whose
values are defined by an array or a List
.
For example to create a model defined by
an array of the names of the days of the week:
String[] days = new DateFormatSymbols().getWeekdays(); SpinnerModel model = new SpinnerListModel(Arrays.asList(days).subList(1, 8));This class only stores a reference to the array or
List
so if an element of the underlying sequence changes, it's up
to the application to notify the ChangeListeners
by calling
fireStateChanged
.
This model inherits a ChangeListener
.
The ChangeListener
s are notified whenever the
model's value
or list
properties changes.
- Since:
- 1.4
- See Also:
-
Field Summary
Fields declared in class javax.swing.AbstractSpinnerModel
listenerList
-
Constructor Summary
ConstructorDescriptionConstructs an effectively emptySpinnerListModel
.SpinnerListModel
(Object[] values) Constructs aSpinnerModel
whose sequence of values is defined by the specified array.SpinnerListModel
(List<?> values) Constructs aSpinnerModel
whose sequence of values is defined by the specifiedList
. -
Method Summary
Modifier and TypeMethodDescriptionList
<?> getList()
Returns theList
that defines the sequence for this model.Returns the next legal value of the underlying sequence ornull
if value is already the last element.Returns the previous element of the underlying sequence ornull
if value is already the first element.getValue()
Returns the current element of the sequence.void
Changes the list that defines this sequence and resets the index of the modelsvalue
to zero.void
Changes the current element of the sequence and notifiesChangeListeners
.Methods declared in class javax.swing.AbstractSpinnerModel
addChangeListener, fireStateChanged, getChangeListeners, getListeners, removeChangeListener
-
Constructor Details
-
SpinnerListModel
Constructs aSpinnerModel
whose sequence of values is defined by the specifiedList
. The initial value (current element) of the model will bevalues.get(0)
. Ifvalues
isnull
or has zero size, anIllegalArugmentException
is thrown.- Parameters:
values
- the sequence this model represents- Throws:
IllegalArgumentException
- ifvalues
isnull
or zero size
-
SpinnerListModel
Constructs aSpinnerModel
whose sequence of values is defined by the specified array. The initial value of the model will bevalues[0]
. Ifvalues
isnull
or has zero length, anIllegalArgumentException
is thrown.- Parameters:
values
- the sequence this model represents- Throws:
IllegalArgumentException
- ifvalues
isnull
or zero length
-
SpinnerListModel
public SpinnerListModel()Constructs an effectively emptySpinnerListModel
. The model's list will contain a single"empty"
string element.
-
-
Method Details
-
getList
Returns theList
that defines the sequence for this model.- Returns:
- the value of the
list
property - See Also:
-
setList
Changes the list that defines this sequence and resets the index of the modelsvalue
to zero. Note thatlist
is not copied, the model just stores a reference to it.This method fires a
ChangeEvent
iflist
is not equal to the current list.- Parameters:
list
- the sequence that this model represents- Throws:
IllegalArgumentException
- iflist
isnull
or zero length- See Also:
-
getValue
Returns the current element of the sequence.- Specified by:
getValue
in interfaceSpinnerModel
- Returns:
- the
value
property - See Also:
-
setValue
Changes the current element of the sequence and notifiesChangeListeners
. If the specified value is not equal to an element of the underlying sequence then anIllegalArgumentException
is thrown. In the following example thesetValue
call would cause an exception to be thrown:String[] values = {"one", "two", "free", "four"}; SpinnerModel model = new SpinnerListModel(values); model.setValue("TWO");
- Specified by:
setValue
in interfaceSpinnerModel
- Parameters:
elt
- the sequence element that will be model's current value- Throws:
IllegalArgumentException
- if the specified value isn't allowed- See Also:
-
getNextValue
Returns the next legal value of the underlying sequence ornull
if value is already the last element.- Specified by:
getNextValue
in interfaceSpinnerModel
- Returns:
- the next legal value of the underlying sequence or
null
if value is already the last element - See Also:
-
getPreviousValue
Returns the previous element of the underlying sequence ornull
if value is already the first element.- Specified by:
getPreviousValue
in interfaceSpinnerModel
- Returns:
- the previous element of the underlying sequence or
null
if value is already the first element - See Also:
-