SpinnerModel (Java Platform SE 8 ) (original) (raw)
- All Known Implementing Classes:
AbstractSpinnerModel, SpinnerDateModel, SpinnerListModel, SpinnerNumberModel
public interface SpinnerModel
A model for a potentially unbounded sequence of object values. This model is similar to ListModel
however there are some important differences:
The number of sequence elements isn't necessarily bounded.
The model doesn't support indexed random access to sequence elements. Only three sequence values are accessible at a time: current, next and previous.
The current sequence element, can be set.
ASpinnerModel
has three properties, only the first is read/write.value
The current element of the sequence.nextValue
The following element or null ifvalue
is the last element of the sequence.previousValue
The preceding element or null ifvalue
is the first element of the sequence.
When the thevalue
property changes,ChangeListeners
are notified.SpinnerModel
may choose to notify theChangeListeners
under other circumstances.
Since:
1.4
See Also:
JSpinner, AbstractSpinnerModel, SpinnerListModel, SpinnerNumberModel, SpinnerDateModelMethod Summary
All Methods Instance Methods Abstract Methods
Modifier and Type Method Description void addChangeListener(ChangeListener l) Adds a ChangeListener to the model's listener list. Object getNextValue() Return the object in the sequence that comes after the object returned by getValue(). Object getPreviousValue() Return the object in the sequence that comes before the object returned by getValue(). Object getValue() The current element of the sequence. void removeChangeListener(ChangeListener l) Removes a ChangeListener from the model's listener list. void setValue(Object value) Changes current value of the model, typically this value is displayed by the editor part of a JSpinner. Method Detail
* #### getValue [Object](../../java/lang/Object.html "class in java.lang") getValue() The _current element_ of the sequence. This element is usually displayed by the `editor` part of a `JSpinner`. Returns: the current spinner value. See Also: [setValue(java.lang.Object)](../../javax/swing/SpinnerModel.html#setValue-java.lang.Object-) * #### setValue void setValue([Object](../../java/lang/Object.html "class in java.lang") value) Changes current value of the model, typically this value is displayed by the `editor` part of a `JSpinner`. If the `SpinnerModel` implementation doesn't support the specified value then an `IllegalArgumentException` is thrown. For example a `SpinnerModel` for numbers might only support values that are integer multiples of ten. In that case, `model.setValue(new Number(11))` would throw an exception. Throws: `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if `value` isn't allowed See Also: [getValue()](../../javax/swing/SpinnerModel.html#getValue--) * #### getNextValue [Object](../../java/lang/Object.html "class in java.lang") getNextValue() Return the object in the sequence that comes after the object returned by `getValue()`. If the end of the sequence has been reached then return null. Calling this method does not effect `value`. Returns: the next legal value or null if one doesn't exist See Also: [getValue()](../../javax/swing/SpinnerModel.html#getValue--), [getPreviousValue()](../../javax/swing/SpinnerModel.html#getPreviousValue--) * #### getPreviousValue [Object](../../java/lang/Object.html "class in java.lang") getPreviousValue() Return the object in the sequence that comes before the object returned by `getValue()`. If the end of the sequence has been reached then return null. Calling this method does not effect `value`. Returns: the previous legal value or null if one doesn't exist See Also: [getValue()](../../javax/swing/SpinnerModel.html#getValue--), [getNextValue()](../../javax/swing/SpinnerModel.html#getNextValue--) * #### addChangeListener void addChangeListener([ChangeListener](../../javax/swing/event/ChangeListener.html "interface in javax.swing.event") l) Adds a `ChangeListener` to the model's listener list. The`ChangeListeners` must be notified when models `value` changes. Parameters: `l` \- the ChangeListener to add See Also: [removeChangeListener(javax.swing.event.ChangeListener)](../../javax/swing/SpinnerModel.html#removeChangeListener-javax.swing.event.ChangeListener-) * #### removeChangeListener void removeChangeListener([ChangeListener](../../javax/swing/event/ChangeListener.html "interface in javax.swing.event") l) Removes a `ChangeListener` from the model's listener list. Parameters: `l` \- the ChangeListener to remove See Also: [addChangeListener(javax.swing.event.ChangeListener)](../../javax/swing/SpinnerModel.html#addChangeListener-javax.swing.event.ChangeListener-)
Submit a bug or feature
For further API reference and developer documentation, see Java SE Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 1993, 2025, Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.