Spinner Models
The javax.swing package
includes several pre-built models for many common data types suited to
spinners. Figure 7-15 shows
the hierarchy of these models.

Figure 7-15. SpinnerModel class diagram
The SpinnerModel Interface
The SpinnerModel interface includes methods required to successfully
store and retrieve spinner data. It includes a read/write value and
next and previous properties, and it forces implementing models (such
as AbstractSpinnerModel) to support
a ChangeListener.
Properties
Not surprisingly, the properties for SpinnerModel are centered on the value
being shown in the spinner. Notice in Table 7-17 that the model
stores only the current value and the next/previous values. The
actual list (or other object) behind these values is not part of the
model.
Table 7-17. SpinnerModel properties
Property | Data type | get | is | set | Default value |
|---|---|---|---|---|---|
nextValue | Object | · | |||
previousValue | Object | · | |||
value | Object | · | · |
Events
Any changes to the selected value should be reported through
ChangeEvent objects.
- public void addChangeListener(ChangeListener l)public void removeChangeListener(ChangeListener l)
Add or remove a specific listener for
ChangeEventnotifications from the component.
The AbstractSpinnerModel Class
The AbstractSpinnerModel
class implements the event parts of the SpinnerModel. Implementations of addChangeListener( ), removeChangeListener( ), and getChange-Listeners( ) are all present. ...