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

Spinners

You might be wondering just what a spinner is. It’s a new 1.4 component similar to the JComboBox, but it shows only one item. It includes up and down arrows to "scroll” through its set of values. A JFormattedTextField is used to edit and render those values. Spinners are quite flexible. They work nicely with a set of choices (such as the months of the year) as well as with unbounded ranges such as a set of integers. Figure 7-13 shows several examples of spinners in different L&Fs. The Mac L&F is missing from this figure because the SDK 1.4 was not available on OS X at the time we went to press.

Various JSpinner instances in three L&Fs

Figure 7-13. Various JSpinner instances in three L&Fs

The classes involved in spinners are shown in Figure 7-14.

JSpinner class diagram

Figure 7-14. JSpinner class diagram

Properties

JSpinner has several properties related to the values it displays (see Table 7-16). Most of the properties are easy to understand from their names alone. The currently selected value is available through the read/write value property.

Table 7-16. JSpinner properties

Property

Data type

get

is

set

Default value

changeListeners

ChangeListener[]

·

  

Empty array

editorb

JComponent

·

 

·

JPspinner.NumberEditor( )

modelb

SpinnerModel

·

 

·

SpinnerNumberModel( )

nextValue

Object

·

   

previousValue

Object

·

   

UI

SpinnerUI

·

  

L&F-dependent

UIClassID

String

·

  

“SpinnerUI” ...

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