|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.AbstractSpinnerModel
javax.swing.SpinnerListModel
public class SpinnerListModel
An implementation of 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()
.
SpinnerModel
,
AbstractSpinnerModel
,
JSpinner
,
Serialized FormField Summary |
---|
Fields inherited from class javax.swing.AbstractSpinnerModel |
---|
listenerList |
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. |
Methods inherited from class javax.swing.AbstractSpinnerModel |
---|
addChangeListener, fireStateChanged, getChangeListeners, getListeners, removeChangeListener |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public SpinnerListModel()
SpinnerListModel
. This
is a model backed by a list containing only the single
String
element, "empty".
public SpinnerListModel(List<?> list)
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)
.
list
- The list to use for this model.
IllegalArgumentException
- if the list is null or contains no
elements.getNextValue()
,
getValue()
public SpinnerListModel(Object[] array)
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]
.
array
- The array to use for this model.
IllegalArgumentException
- if the array is null or contains
no elements.Arrays.asList(Object[])
,
getNextValue()
,
getValue()
Method Detail |
---|
public List<?> getList()
public Object getNextValue()
getNextValue
in interface SpinnerModel
public Object getPreviousValue()
getPreviousValue
in interface SpinnerModel
public Object getValue()
getNextValue()
or getPreviousValue()
.
getValue
in interface SpinnerModel
getPreviousValue()
,
getNextValue()
public void setList(List<?> list)
ChangeEvent
is fired if the list being used actually
changes (i.e. the new list is not referentially equal (!=) to the
old one).
list
- The new list to use.
IllegalArgumentException
- if the list is null or contains
no elements.ChangeEvent
public void setValue(Object value)
getNextValue()
and
getPreviousValue()
return the objects following
and prior to the supplied value, respectively.
setValue
in interface SpinnerModel
value
- The requested new value of the list.
IllegalArgumentException
- if the supplied value does
not exist in the backing list.getPreviousValue()
,
getNextValue()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |