- java.lang.Object
-
- javax.swing.AbstractSpinnerModel
-
- javax.swing.SpinnerListModel
-
- All Implemented Interfaces:
- Serializable, SpinnerModel
public class SpinnerListModel extends AbstractSpinnerModel implements Serializable
A simple implementation ofSpinnerModel
whose values are defined by an array or aList
. 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 orList
so if an element of the underlying sequence changes, it's up to the application to notify theChangeListeners
by callingfireStateChanged
.This model inherits a
ChangeListener
. TheChangeListener
s are notified whenever the model'svalue
orlist
properties changes.- Since:
- 1.4
- See Also:
JSpinner
,SpinnerModel
,AbstractSpinnerModel
,SpinnerNumberModel
,SpinnerDateModel
-
-
Field Summary
-
Fields inherited from class javax.swing.AbstractSpinnerModel
listenerList
-
-
Constructor Summary
Constructors Constructor and Description SpinnerListModel()
Constructs an effectively emptySpinnerListModel
.SpinnerListModel(List<?> values)
Constructs aSpinnerModel
whose sequence of values is defined by the specifiedList
.SpinnerListModel(Object[] values)
Constructs aSpinnerModel
whose sequence of values is defined by the specified array.
-
Method Summary
Methods Modifier and Type Method and Description List<?>
getList()
Returns theList
that defines the sequence for this model.Object
getNextValue()
Returns the next legal value of the underlying sequence ornull
if value is already the last element.Object
getPreviousValue()
Returns the previous element of the underlying sequence ornull
if value is already the first element.Object
getValue()
Returns the current element of the sequence.void
setList(List<?> list)
Changes the list that defines this sequence and resets the index of the modelsvalue
to zero.void
setValue(Object elt)
Changes the current element of the sequence and notifiesChangeListeners
.-
Methods inherited from class javax.swing.AbstractSpinnerModel
addChangeListener, fireStateChanged, getChangeListeners, getListeners, removeChangeListener
-
-
-
-
Constructor Detail
-
SpinnerListModel
public SpinnerListModel(List<?> values)
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:
IllegalArugmentException
- ifvalues
isnull
or zero size
-
SpinnerListModel
public SpinnerListModel(Object[] values)
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, anIllegalArugmentException
is thrown.- Parameters:
values
- the sequence this model represents- Throws:
IllegalArugmentException
- ifvalues
isnull
or zero length
-
SpinnerListModel
public SpinnerListModel()
Constructs an effectively emptySpinnerListModel
. The model's list will contain a single"empty"
string element.
-
-
Method Detail
-
getList
public List<?> getList()
Returns theList
that defines the sequence for this model.- Returns:
- the value of the
list
property - See Also:
setList(java.util.List<?>)
-
setList
public void setList(List<?> list)
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:
getList()
-
getValue
public Object getValue()
Returns the current element of the sequence.- Specified by:
getValue
in interfaceSpinnerModel
- Returns:
- the
value
property - See Also:
SpinnerModel.getValue()
,setValue(java.lang.Object)
-
setValue
public void setValue(Object elt)
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:
SpinnerModel.setValue(java.lang.Object)
,getValue()
-
getNextValue
public Object 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:
SpinnerModel.getNextValue()
,getPreviousValue()
-
getPreviousValue
public Object 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:
SpinnerModel.getPreviousValue()
,getNextValue()
-
-
Traduction non disponible
Les API Java ne sont pas encore traduites en français sur l'infobrol. Seule la version anglaise est disponible pour l'instant.
Version en cache
22/12/2024 15:05:10 Cette version de la page est en cache (à la date du 22/12/2024 15:05:10) afin d'accélérer le traitement. Vous pouvez activer le mode utilisateur dans le menu en haut pour afficher la dernère version de la page.Document créé le 29/08/2006, dernière modification le 04/03/2020
Source du document imprimé : https://www.gaudry.be/java-api-rf-javax/swing/spinnerlistmodel.html
L'infobrol est un site personnel dont le contenu n'engage que moi. Le texte est mis à disposition sous licence CreativeCommons(BY-NC-SA). Plus d'info sur les conditions d'utilisation et sur l'auteur.
Références
Ces références et liens indiquent des documents consultés lors de la rédaction de cette page, ou qui peuvent apporter un complément d'information, mais les auteurs de ces sources ne peuvent être tenus responsables du contenu de cette page.
L'auteur de ce site est seul responsable de la manière dont sont présentés ici les différents concepts, et des libertés qui sont prises avec les ouvrages de référence. N'oubliez pas que vous devez croiser les informations de sources multiples afin de diminuer les risques d'erreurs.