SpinnerNumberModel Class

Package: javax.swing

Using this provides an implementation of the SpinnerModel interface from which you create JSpinner controls that let the user select from a range of numbers.

CrossRef.eps For more information, see JSpinner Class.

Constructors

Constructor

Description

SpinnerNumberModel(int init, int min, int max, int step)

Creates a number spinner model that lets the user select integer values ranging from min to max, with an increment of step. The initial value is set to init.

SpinnerNumberModel (double max, double step)

Creates a number spinner model that lets the user select double values ranging from min to max, with an increment of step. The initial value is set to init.

The first, SpinnerNumberModel, creates numeric spinner controls that let you control the initial value, the minimum and maximum values, and the step value that’s added or subtracted each time the user clicks one of the arrows.

Here’s how you can use the SpinnerNumberModel to create a spinner that accepts integers from 1 to 12, starting with 1:

JSpinner hours = new JSpinner(

new SpinnerNumberModel(1, 1, 12, 1));

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.