Module java.desktop
Package javax.swing

Class SpinnerNumberModel

java.lang.Object
javax.swing.AbstractSpinnerModel
javax.swing.SpinnerNumberModel
All Implemented Interfaces:
Serializable, SpinnerModel

public class SpinnerNumberModel extends AbstractSpinnerModel implements Serializable
A SpinnerModel for sequences of numbers. The upper and lower bounds of the sequence are defined by properties called minimum and maximum. The size of the increase or decrease computed by the nextValue and previousValue methods is defined by a property called stepSize. The minimum and maximum properties can be null to indicate that the sequence has no lower or upper limit. All of the properties in this class are defined in terms of two generic types: Number and Comparable, so that all Java numeric types may be accommodated. Internally, there's only support for values whose type is one of the primitive Number types: Double, Float, Long, Integer, Short, or Byte.

To create a SpinnerNumberModel for the integer range zero to one hundred, with fifty as the initial value, one could write:

 Integer value = Integer.valueOf(50);
 Integer min = Integer.valueOf(0);
 Integer max = Integer.valueOf(100);
 Integer step = Integer.valueOf(1);
 SpinnerNumberModel model = new SpinnerNumberModel(value, min, max, step);
 int fifty = model.getNumber().intValue();
 

Spinners for integers and doubles are common, so special constructors for these cases are provided. For example to create the model in the previous example, one could also write:

 SpinnerNumberModel model = new SpinnerNumberModel(50, 0, 100, 1);
 

This model inherits a ChangeListener. The ChangeListeners are notified whenever the model's value, stepSize, minimum, or maximum properties changes.

Since:
1.4
See Also: