JSpinner Class

Package: javax.swing

Using this creates a spinner control, which is a text field that has two little arrows next to it that allow the user to increase or decrease the value in the text field. Usually, the text field contains a number, so clicking one of the little arrows increments or decrements the number. You can also create a spinner that displays data taken from an array or a collection.

Figure 5-11 shows three spinners arranged as a simple time picker.

9781118239742-fg0511.tif

Figure 5-11

This class can be used in conjunction with the SpinnerModel interface and two classes that implement it: Spinner NumberModel and SpinnerListModel. For more information, see SpinnerNumberModel Class and SpinnerListModel Class.

Constructors

Constructor

Description

JSpinner()

Creates a default spinner. The default spinner lets the user choose an integer that has an initial value of 0 and no minimum or maximum values.

JSlider(SpinnerModel model)

Creates a spinner using the specified SpinnerModel object.

Methods

Method

Description

void addChangeListener(ChangeListener listener)

Adds a ChangeListener to listen for change events

int getValue()

Gets the value

void setToolTipText(String ext)

Sets the tooltip text that’s displayed if the user rests the mouse over the slider for a few moments

You can create a default spinner that lets the user select integer ...

Get Java For Dummies Quick Reference now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.