Java Reference
In-Depth Information
When no arguments are provided, the model contains a single element: the string empty .
The List version retains a reference to the list. It does not copy the list. If you change the list,
you change the elements in the model. The array version creates a private inner class instance
of a List that can't be added to. For both the List and array versions, the initial selection will
be the first element. If either is empty, an IllegalArgumentException will be thrown.
As shown in Table 14-4, the only property added beyond those from the interface is to get
or set the list.
Table 14-4. SpinnerListModel Properties
Property Name
Data Type
Access
list
List<?>
Read-write
nextValue
Object
Read-only
previousValue
Object
Read-only
value
Object
Read-write
SpinnerNumberModel Class
The SpinnerNumberModel provides for the selection of a number from an open or closed range
of values. That number can be any of the subclasses of Number , including Integer and Double .
It has four constructors, with the first three provided just as convenience methods to the last.
public SpinnerNumberModel()
SpinnerModel model = new SpinnerNumberModel();
JSpinner spinner = new JSpinner(model);
public SpinnerNumberModel(double value, double minimum, double maximum,
double stepSize)
SpinnerModel model = new SpinnerNumberModel(50, 0, 100, .25);
JSpinner spinner = new JSpinner(model);
public SpinnerNumberModel(int value, int minimum, int maximum, int stepSize)
SpinnerModel model = new SpinnerNumberModel(50, 0, 100, 1);
JSpinner spinner = new JSpinner(model);
public SpinnerNumberModel(Number value, Comparable minimum, Comparable maximum,
Number stepSize)
Number value = new Integer(50);
Number min = new Integer(0);
Number max = new Integer(100);
Number step = new Integer(1);
SpinnerModel model = new SpinnerNumberModel(value, min, max, step);
JSpinner spinner = new JSpinner(model);
Search WWH ::




Custom Search