javax.swing

Class SpinnerNumberModel

public class SpinnerNumberModel extends AbstractSpinnerModel implements Serializable

A model used by the {@link JSpinner} component.

Since: 1.4

Constructor Summary
SpinnerNumberModel()
Creates a SpinnerNumberModel with initial value 0, step 1, and no maximum nor minimum.
SpinnerNumberModel(double value, double minimum, double maximum, double stepSize)
Creates a SpinnerNumberModel with double precision.
SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)
Creates a SpinnerNumberModel with integer precision.
SpinnerNumberModel(Number value, Comparable minimum, Comparable maximum, Number stepSize)
Creates a SpinnerNumberModel with the given attributes.
Method Summary
ComparablegetMaximum()
Returns the maximum value, or null if there is no maximum.
ComparablegetMinimum()
Returns the minimum value, or null if there is no minimum.
ObjectgetNextValue()
Returns the next value, or null if adding the step size to the current value results in a value greater than the maximum value.
NumbergetNumber()
Returns the current value.
ObjectgetPreviousValue()
Returns the previous value, or null if subtracting the step size from the current value results in a value less than the minimum value.
NumbergetStepSize()
Returns the step size.
ObjectgetValue()
Returns the current value, which for this class is always an instance of {@link Number}.
voidsetMaximum(Comparable newMaximum)
Sets the maximum value and, if the new value is different to the old value, sends a {@link ChangeEvent} to all registered listeners.
voidsetMinimum(Comparable newMinimum)
Sets the minimum value and, if the new value is different to the old value, sends a {@link ChangeEvent} to all registered listeners.
voidsetStepSize(Number newStepSize)
Sets the step size and, if the new step size is different to the old step size, sends a {@link ChangeEvent} to all registered listeners.
voidsetValue(Object value)
Sets the current value and, if the new value is different to the old value, sends a {@link ChangeEvent} to all registered listeners.

Constructor Detail

SpinnerNumberModel

public SpinnerNumberModel()
Creates a SpinnerNumberModel with initial value 0, step 1, and no maximum nor minimum.

SpinnerNumberModel

public SpinnerNumberModel(double value, double minimum, double maximum, double stepSize)
Creates a SpinnerNumberModel with double precision.

Parameters: value the initial value minimum the minimum value maximum the maximum value stepSize the step size

Throws: IllegalArgumentException if minimum <= value <= maximum does not hold.

SpinnerNumberModel

public SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)
Creates a SpinnerNumberModel with integer precision.

Parameters: value the initial value minimum the minimum value maximum the maximum value stepSize the step size

Throws: IllegalArgumentException if minimum <= value <= maximum does not hold.

SpinnerNumberModel

public SpinnerNumberModel(Number value, Comparable minimum, Comparable maximum, Number stepSize)
Creates a SpinnerNumberModel with the given attributes. The caller should ensure that both minimum and maximum are serializable.

Parameters: value the initial value (null not permitted). minimum the minimum value (null permitted). maximum the maximum value (null permitted). stepSize the step size (null not permitted).

Throws: IllegalArgumentException if minimum <= value <= maximum does not hold IllegalArgumentException if value is null. IllegalArgumentException if stepSize is null.

Method Detail

getMaximum

public Comparable getMaximum()
Returns the maximum value, or null if there is no maximum.

Returns: The maximum value.

See Also: getMinimum setMaximum

getMinimum

public Comparable getMinimum()
Returns the minimum value, or null if there is no minimum.

Returns: The minimum value.

See Also: setMinimum

getNextValue

public Object getNextValue()
Returns the next value, or null if adding the step size to the current value results in a value greater than the maximum value. The current value is not changed.

Returns: The next value, or null if the current value is the maximum value represented by this model.

getNumber

public Number getNumber()
Returns the current value.

Returns: The current value.

getPreviousValue

public Object getPreviousValue()
Returns the previous value, or null if subtracting the step size from the current value results in a value less than the minimum value. The current value is not changed.

Returns: The previous value, or null if the current value is the minimum value represented by this model.

getStepSize

public Number getStepSize()
Returns the step size.

Returns: The step size (never null).

getValue

public Object getValue()
Returns the current value, which for this class is always an instance of {@link Number}.

Returns: The current value.

See Also: getNumber

setMaximum

public void setMaximum(Comparable newMaximum)
Sets the maximum value and, if the new value is different to the old value, sends a {@link ChangeEvent} to all registered listeners. A null value is interpreted as "no maximum value". No check is made to ensure that the new maximum is greater than or equal to the current value, the caller is responsible for ensuring that this relationship holds. In addition, the caller should ensure that newMaximum is {@link Serializable}.

Parameters: newMaximum the new maximum (null permitted).

See Also: getMaximum

setMinimum

public void setMinimum(Comparable newMinimum)
Sets the minimum value and, if the new value is different to the old value, sends a {@link ChangeEvent} to all registered listeners. A null value is interpreted as "no minimum value". No check is made to ensure that the new minimum is less than or equal to the current value, the caller is responsible for ensuring that this relationship holds. In addition, the caller should ensure that newMinimum is {@link Serializable}.

Parameters: newMinimum the new minimum value (null permitted).

See Also: getMinimum

setStepSize

public void setStepSize(Number newStepSize)
Sets the step size and, if the new step size is different to the old step size, sends a {@link ChangeEvent} to all registered listeners.

Parameters: newStepSize the new step size (null not permitted).

Throws: IllegalArgumentException if newStepSize is null.

setValue

public void setValue(Object value)
Sets the current value and, if the new value is different to the old value, sends a {@link ChangeEvent} to all registered listeners.

Parameters: value the new value (null not permitted, must be an instance of Number).

Throws: IllegalArgumentException if value is not an instance of Number.