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.
JSpinner, SpinnerModel, AbstractSpinnerModel, SpinnerListModel, SpinnerDateModel
| Modifier and Type | Field and Description |
|---|---|
| private Comparable | |
| private Comparable | |
| private Number | |
| private Number |
| Access | Constructor and Description |
|---|---|
| public | SpinnerNumberModel(Number
the current (non value, Comparable<?> null) value of the modelthe first number in the sequence or minimum, Comparable<?> nullthe last number in the sequence or maximum, Number nullthe difference between elements of the sequence stepSize)Constructs a |
| public | SpinnerNumberModel(int
the current value of the model value, int the first number in the sequence minimum, int the last number in the sequence maximum, int the difference between elements of the sequence stepSize)Constructs a |
| public | SpinnerNumberModel(double
the current value of the model value, double the first number in the sequence minimum, double the last number in the sequence maximum, double the difference between elements of the sequence stepSize)Constructs a |
| public | SpinnerNumberModel()
Constructs a |
| Modifier and Type | Method and Description |
|---|---|
| public Comparable | |
| public Comparable | |
| public Object | Returns: value + stepSize or null if the sum
exceeds maximum.Implements javax. Returns the next number in the sequence. |
| public Number | |
| public Object | Returns: value - stepSize, or
null if the sum is less
than minimum.Implements javax. Returns the previous number in the sequence. |
| public Number | Returns: the value of thestepSize propertyReturns the size of the value change computed by the
|
| public Object | Returns: the value propertyImplements javax. Returns the value of the current element of the sequence. |
| private Number | |
| public void | setMaximum(Comparable<?>
a maximum)Comparable that has a
compareTo method for Numbers with
the same type as valueChanges the upper bound for numbers in this sequence. |
| public void | setMinimum(Comparable<?>
a minimum)Comparable that has a
compareTo method for Numbers with
the same type as valueChanges the lower bound for numbers in this sequence. |
| public void | setStepSize(Number
the size of the value change computed by the
stepSize)getNextValue and getPreviousValue methodsChanges the size of the value change computed by the
|
| public void | setValue(Object
the current (non value)null) Number
for this sequenceImplements javax. Sets the current value for this sequence. |
| maximum | back to summary |
|---|---|
| private Comparable<?> maximum | |
| minimum | back to summary |
|---|---|
| private Comparable<?> minimum | |
| stepSize | back to summary |
|---|---|
| private Number stepSize | |
| value | back to summary |
|---|---|
| private Number value | |
| SpinnerNumberModel | back to summary |
|---|---|
| public SpinnerNumberModel(Number value, Comparable<?> minimum, Comparable<?> maximum, Number stepSize) Constructs a
The
| |
| SpinnerNumberModel | back to summary |
|---|---|
| public SpinnerNumberModel(int value, int minimum, int maximum, int stepSize) Constructs a
| |
| SpinnerNumberModel | back to summary |
|---|---|
| public SpinnerNumberModel(double value, double minimum, double maximum, double stepSize) Constructs a
| |
| SpinnerNumberModel | back to summary |
|---|---|
| public SpinnerNumberModel() Constructs a | |
| getMaximum | back to summary |
|---|---|
| public Comparable Returns the last number in the sequence.
| |
| getMinimum | back to summary |
|---|---|
| public Comparable Returns the first number in this sequence.
| |
| getNextValue | back to summary |
|---|---|
| public Object getNextValue() Implements javax. Returns the next number in the sequence.
| |
| getNumber | back to summary |
|---|---|
| public Number getNumber() Returns the value of the current element of the sequence. | |
| getPreviousValue | back to summary |
|---|---|
| public Object getPreviousValue() Implements javax. Returns the previous number in the sequence.
| |
| getStepSize | back to summary |
|---|---|
| public Number getStepSize() Returns the size of the value change computed by the
| |
| getValue | back to summary |
|---|---|
| public Object getValue() Implements javax. Returns the value of the current element of the sequence. | |
| incrValue | back to summary |
|---|---|
private Number incrValue(int dir)
| |
| setMaximum | back to summary |
|---|---|
| public void setMaximum(Comparable<?> maximum) Changes the upper bound for numbers in this sequence.
If
Typically this property is a
This method fires a
| |
| setMinimum | back to summary |
|---|---|
| public void setMinimum(Comparable<?> minimum) Changes the lower bound for numbers in this sequence.
If
Typically this property is a
MyDate extends Date { // Date already implements Comparable
public int compareTo(Long o) {
long t = getTime();
return (t < o.longValue() ? -1 : (t == o.longValue() ? 0 : 1));
}
}
This method fires a
| |
| setStepSize | back to summary |
|---|---|
| public void setStepSize(Number stepSize) Changes the size of the value change computed by the
This method fires a
| |
| setValue | back to summary |
|---|---|
| public void setValue(Object value) Implements javax. Sets the current value for this sequence. If
This method fires a
| |