APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing

public Class SpinnerListModel

extends AbstractSpinnerModel
implements Serializable
Class Inheritance
All Implemented Interfaces
java.io.Serializable
Annotations
@SuppressWarnings:serial
Imports
java.util.*, java.io.Serializable

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 ChangeListeners are notified whenever the model's value or list properties changes.

Author
Hans Muller
Since
1.4
See Also
JSpinner, SpinnerModel, AbstractSpinnerModel, SpinnerNumberModel, SpinnerDateModel

Field Summary

Modifier and TypeField and Description
private int
private List<?>
Inherited from javax.swing.AbstractSpinnerModel:
listenerList

Constructor Summary

AccessConstructor and Description
public
SpinnerListModel(List<?>
the sequence this model represents
values
)

Constructs a SpinnerModel whose sequence of values is defined by the specified List.

public
SpinnerListModel(Object[]
the sequence this model represents
values
)

Constructs a SpinnerModel whose sequence of values is defined by the specified array.

public
SpinnerListModel()

Constructs an effectively empty SpinnerListModel.

Method Summary

Modifier and TypeMethod and Description
pack-priv Object

Returns:

the match
findNextMatch
(String
the string to be matched
substring
)

Returns the next object that starts with substring.

public List<?>

Returns:

the value of the list property
getList
()

Returns the List that defines the sequence for this model.

public Object

Returns:

the next legal value of the underlying sequence or null if value is already the last element
getNextValue
()

Implements javax.swing.SpinnerModel.getNextValue.

Returns the next legal value of the underlying sequence or null if value is already the last element.

public Object

Returns:

the previous element of the underlying sequence or null if value is already the first element
getPreviousValue
()

Implements javax.swing.SpinnerModel.getPreviousValue.

Returns the previous element of the underlying sequence or null if value is already the first element.

public Object

Returns:

the value property
getValue
()

Implements javax.swing.SpinnerModel.getValue.

Returns the current element of the sequence.

public void
setList(List<?>
the sequence that this model represents
list
)

Changes the list that defines this sequence and resets the index of the models value to zero.

public void
setValue(Object
the sequence element that will be model's current value
elt
)

Implements javax.swing.SpinnerModel.setValue.

Changes the current element of the sequence and notifies ChangeListeners.

Inherited from javax.swing.AbstractSpinnerModel:
addChangeListenerfireStateChangedgetChangeListenersgetListenersremoveChangeListener

Field Detail

indexback to summary
private int index
listback to summary
private List<?> list

Constructor Detail

SpinnerListModelback to summary
public SpinnerListModel(List<?> values)

Constructs a SpinnerModel whose sequence of values is defined by the specified List. The initial value (current element) of the model will be values.get(0). If values is null or has zero size, an IllegalArgumentException is thrown.

Parameters
values:List<?>

the sequence this model represents

Exceptions
IllegalArgumentException:
if values is null or zero size
SpinnerListModelback to summary
public SpinnerListModel(Object[] values)

Constructs a SpinnerModel whose sequence of values is defined by the specified array. The initial value of the model will be values[0]. If values is null or has zero length, an IllegalArgumentException is thrown.

Parameters
values:Object[]

the sequence this model represents

Exceptions
IllegalArgumentException:
if values is null or zero length
SpinnerListModelback to summary
public SpinnerListModel()

Constructs an effectively empty SpinnerListModel. The model's list will contain a single "empty" string element.

Method Detail

findNextMatchback to summary
pack-priv Object findNextMatch(String substring)

Returns the next object that starts with substring.

Parameters
substring:String

the string to be matched

Returns:Object

the match

getListback to summary
public List<?> getList()

Returns the List that defines the sequence for this model.

Returns:List<?>

the value of the list property

See Also
setList
getNextValueback to summary
public Object getNextValue()

Implements javax.swing.SpinnerModel.getNextValue.

Returns the next legal value of the underlying sequence or null if value is already the last element.

Returns:Object

the next legal value of the underlying sequence or null if value is already the last element

See Also
SpinnerModel#getNextValue, getPreviousValue
getPreviousValueback to summary
public Object getPreviousValue()

Implements javax.swing.SpinnerModel.getPreviousValue.

Returns the previous element of the underlying sequence or null if value is already the first element.

Returns:Object

the previous element of the underlying sequence or null if value is already the first element

See Also
SpinnerModel#getPreviousValue, getNextValue
getValueback to summary
public Object getValue()

Implements javax.swing.SpinnerModel.getValue.

Returns the current element of the sequence.

Returns:Object

the value property

See Also
SpinnerModel#getValue, setValue
setListback to summary
public void setList(List<?> list)

Changes the list that defines this sequence and resets the index of the models value to zero. Note that list is not copied, the model just stores a reference to it.

This method fires a ChangeEvent if list is not equal to the current list.

Parameters
list:List<?>

the sequence that this model represents

Exceptions
IllegalArgumentException:
if list is null or zero length
See Also
getList
setValueback to summary
public void setValue(Object elt)

Implements javax.swing.SpinnerModel.setValue.

Changes the current element of the sequence and notifies ChangeListeners. If the specified value is not equal to an element of the underlying sequence then an IllegalArgumentException is thrown. In the following example the setValue call would cause an exception to be thrown:

String[] values = {"one", "two", "free", "four"};
SpinnerModel model = new SpinnerListModel(values);
model.setValue("TWO");
Parameters
elt:Object

the sequence element that will be model's current value

Exceptions
IllegalArgumentException:
if the specified value isn't allowed
See Also
SpinnerModel#setValue, getValue