O'Reilly logo

Java Swing, 2nd Edition by Brian Cole, James Elliott, Marc Loy, Robert Eckstein, Dave Wood

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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.

SpinnerModel class diagram

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 ChangeEvent notifications 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. ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required