SpinnerNumberModel (Java Platform SE 8 ) (original) (raw)

A SpinnerModel for sequences of numbers. The upper and lower bounds of the sequence are defined by properties called minimum andmaximum. The size of the increase or decrease computed by the nextValue andpreviousValue methods is defined by a property calledstepSize. The minimum andmaximum 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 andComparable, 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 = new Integer(50); Integer min = new Integer(0); Integer max = new Integer(100); Integer step = new Integer(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.