Skip to Main Content
Java Swing, 2nd Edition
book

Java Swing, 2nd Edition

by Dave Wood, Robert Eckstein, Marc Loy, James Elliott, Brian Cole
November 2002
Intermediate to advanced content levelIntermediate to advanced
1278 pages
38h 26m
English
O'Reilly Media, Inc.
Content preview from Java Swing, 2nd Edition

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” ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Java Threads, 3rd Edition

Java Threads, 3rd Edition

Scott Oaks, Henry Wong

Publisher Resources

ISBN: 0596004087Errata PageSupplemental Content