- java.lang.Object
-
- javax.swing.AbstractSpinnerModel
-
- javax.swing.SpinnerListModel
-
- All Implemented Interfaces:
- Serializable, SpinnerModel
public class SpinnerListModel extends AbstractSpinnerModel implements Serializable
A simple implementation ofSpinnerModelwhose 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 orListso if an element of the underlying sequence changes, it's up to the application to notify theChangeListenersby callingfireStateChanged.This model inherits a
ChangeListener. TheChangeListeners are notified whenever the model'svalueorlistproperties 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 aSpinnerModelwhose sequence of values is defined by the specifiedList.SpinnerListModel(Object[] values)Constructs aSpinnerModelwhose sequence of values is defined by the specified array.
-
Method Summary
Methods Modifier and Type Method and Description List<?>getList()Returns theListthat defines the sequence for this model.ObjectgetNextValue()Returns the next legal value of the underlying sequence ornullif value is already the last element.ObjectgetPreviousValue()Returns the previous element of the underlying sequence ornullif value is already the first element.ObjectgetValue()Returns the current element of the sequence.voidsetList(List<?> list)Changes the list that defines this sequence and resets the index of the modelsvalueto zero.voidsetValue(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 aSpinnerModelwhose sequence of values is defined by the specifiedList. The initial value (current element) of the model will bevalues.get(0). Ifvaluesisnullor has zero size, anIllegalArugmentExceptionis thrown.- Parameters:
values- the sequence this model represents- Throws:
IllegalArugmentException- ifvaluesisnullor zero size
-
SpinnerListModel
public SpinnerListModel(Object[] values)
Constructs aSpinnerModelwhose sequence of values is defined by the specified array. The initial value of the model will bevalues[0]. Ifvaluesisnullor has zero length, anIllegalArugmentExceptionis thrown.- Parameters:
values- the sequence this model represents- Throws:
IllegalArugmentException- ifvaluesisnullor 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 theListthat defines the sequence for this model.- Returns:
- the value of the
listproperty - 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 modelsvalueto zero. Note thatlistis not copied, the model just stores a reference to it.This method fires a
ChangeEventiflistis not equal to the current list.- Parameters:
list- the sequence that this model represents- Throws:
IllegalArgumentException- iflistisnullor zero length- See Also:
getList()
-
getValue
public Object getValue()
Returns the current element of the sequence.- Specified by:
getValuein interfaceSpinnerModel- Returns:
- the
valueproperty - 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 anIllegalArgumentExceptionis thrown. In the following example thesetValuecall would cause an exception to be thrown:String[] values = {"one", "two", "free", "four"}; SpinnerModel model = new SpinnerListModel(values); model.setValue("TWO");- Specified by:
setValuein 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 ornullif value is already the last element.- Specified by:
getNextValuein interfaceSpinnerModel- Returns:
- the next legal value of the underlying sequence or
nullif value is already the last element - See Also:
SpinnerModel.getNextValue(),getPreviousValue()
-
getPreviousValue
public Object getPreviousValue()
Returns the previous element of the underlying sequence ornullif value is already the first element.- Specified by:
getPreviousValuein interfaceSpinnerModel- Returns:
- the previous element of the underlying sequence or
nullif value is already the first element - See Also:
SpinnerModel.getPreviousValue(),getNextValue()
-
-
Deutsche Übersetzung
Sie haben gebeten, diese Seite auf Deutsch zu besuchen. Momentan ist nur die Oberfläche übersetzt, aber noch nicht der gesamte Inhalt.Wenn Sie mir bei Übersetzungen helfen wollen, ist Ihr Beitrag willkommen. Alles, was Sie tun müssen, ist, sich auf der Website zu registrieren und mir eine Nachricht zu schicken, in der Sie gebeten werden, Sie der Gruppe der Übersetzer hinzuzufügen, die Ihnen die Möglichkeit gibt, die gewünschten Seiten zu übersetzen. Ein Link am Ende jeder übersetzten Seite zeigt an, dass Sie der Übersetzer sind und einen Link zu Ihrem Profil haben.
Vielen Dank im Voraus.
Dokument erstellt 11/06/2005, zuletzt geändert 04/03/2020
Quelle des gedruckten Dokuments:https://www.gaudry.be/de/java-api-rf-javax/swing/SpinnerListModel.html
Die Infobro ist eine persönliche Seite, deren Inhalt in meiner alleinigen Verantwortung liegt. Der Text ist unter der CreativeCommons-Lizenz (BY-NC-SA) verfügbar. Weitere Informationen auf die Nutzungsbedingungen und dem Autor.
Referenzen
Diese Verweise und Links verweisen auf Dokumente, die während des Schreibens dieser Seite konsultiert wurden, oder die zusätzliche Informationen liefern können, aber die Autoren dieser Quellen können nicht für den Inhalt dieser Seite verantwortlich gemacht werden.
Der Autor dieser Website ist allein dafür verantwortlich, wie die verschiedenen Konzepte und Freiheiten, die mit den Nachschlagewerken gemacht werden, hier dargestellt werden. Denken Sie daran, dass Sie mehrere Quellinformationen austauschen müssen, um das Risiko von Fehlern zu reduzieren.