Spec-Zone.ru › OpenJDK 27

Class SpinnerListModel

java.lang.Object
javax.swing.AbstractSpinnerModel
javax.swing.SpinnerListModel
All Implemented Interfaces:
Serializable, SpinnerModel
public class SpinnerListModel extends AbstractSpinnerModel implements 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.

Since:
1.4
See Also:
  • JSpinner
  • SpinnerModel
  • AbstractSpinnerModel
  • SpinnerNumberModel
  • SpinnerDateModel

Field Summary

Fields declared in class AbstractSpinnerModel

listenerList
Modifier and Type Field Description
protected EventListenerList listenerList
The list of ChangeListeners for this model.

Constructor Summary

Constructor Description
SpinnerListModel()
Constructs an effectively empty SpinnerListModel.
SpinnerListModel(Object[] values)
Constructs a SpinnerModel whose sequence of values is defined by the specified array.
SpinnerListModel(List<?> values)
Constructs a SpinnerModel whose sequence of values is defined by the specified List.

Method Summary

Modifier and Type Method Description
List<?> getList()
Returns the List that defines the sequence for this model.
Object getNextValue()
Returns the next legal value of the underlying sequence or null if value is already the last element.
Object getPreviousValue()
Returns the previous element of the underlying sequence or null 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 models value to zero.
void setValue(Object elt)
Changes the current element of the sequence and notifies ChangeListeners.

Methods declared in class AbstractSpinnerModel

addChangeListener, fireStateChanged, getChangeListeners, getListeners, removeChangeListener
Modifier and Type Method Description
void addChangeListener(ChangeListener l)
Adds a ChangeListener to the model's listener list.
protected void fireStateChanged()
Run each ChangeListeners stateChanged() method.
ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListeners added to this AbstractSpinnerModel with addChangeListener().
<T extends EventListener>
T[]
getListeners(Class<T> listenerType)
Return an array of all the listeners of the given type that were added to this model.
void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the model's listener list.

Methods declared in class Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Modifier and Type Method Description
protected Object clone()
Creates and returns a copy of this object.
boolean equals(Object obj)
Indicates whether some other object is "equal to" this one.
protected void finalize()
Deprecated, for removal: This API element is subject to removal in a future version.
Finalization is deprecated and subject to removal in a future release.
final Class<?> getClass()
Returns the runtime class of this Object.
int hashCode()
Returns a hash code value for this object.
final void notify()
Wakes up a single thread that is waiting on this object's monitor.
final void notifyAll()
Wakes up all threads that are waiting on this object's monitor.
String toString()
Returns a string representation of the object.
final void wait()
Causes the current thread to wait until it is awakened, typically by being notified or interrupted.
final void wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.
final void wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed.

Constructor Details

SpinnerListModel

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 - the sequence this model represents
Throws:
IllegalArgumentException - if values is null or zero size

SpinnerListModel

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 - the sequence this model represents
Throws:
IllegalArgumentException - if values is null or zero length

SpinnerListModel

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

Method Details

getList

public List<?> getList()
Returns the List that defines the sequence for this model.
Returns:
the value of the list property
See Also:
  • setList(List)

setList

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 - the sequence that this model represents
Throws:
IllegalArgumentException - if list is null or zero length
See Also:
  • getList()

getValue

public Object getValue()
Returns the current element of the sequence.
Specified by:
getValue in interface SpinnerModel
Returns:
the value property
See Also:
  • SpinnerModel.getValue()
  • setValue(Object)

setValue

public void setValue(Object elt)
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");
Specified by:
setValue in interface SpinnerModel
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(Object)
  • getValue()

getNextValue

public Object getNextValue()
Returns the next legal value of the underlying sequence or null if value is already the last element.
Specified by:
getNextValue in interface SpinnerModel
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 or null if value is already the first element.
Specified by:
getPreviousValue in interface SpinnerModel
Returns:
the previous element of the underlying sequence or null if value is already the first element
See Also:
  • SpinnerModel.getPreviousValue()
  • getNextValue()

Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples. Other versions.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2026, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.

© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API