Java Reference
In-Depth Information
Creating JSpinner Components
The
JSpinner
class includes two constructors for initializing the component:
public JSpinner()
JSpinner spinner = new JSpinner();
public JSpinner(SpinnerModel model)
SpinnerModel model = new SpinnerListModel(args);
JSpinner spinner = new JSpinner(model);
You can start with no data model and associate it later with the tracking method of
JSpinner
.
Alternatively, you can start up the component with a full model, in an implementation of the
SpinnerModel
interface, of which three concrete subclasses are available:
SpinnerDateModel
,
SpinnerListModel
, and
SpinnerNumberModel
, along with their abstract parent class
AbstractSpinnerModel
. If you don't specify a model, the
SpinnerNumberModel
is used. While the
renderer and editor for the component is a
JFormattedTextField
, the editing is basically done
through a series of inner classes of
JSpinner
:
DateEditor
,
ListEditor
, and
NumberFormat
, with
its support class in its parent
DefaultEditor
.
JSpinner Properties
In addition to creating the
JSpinner
object, you can certainly reconfigure it, through one of the
nine properties listed in Table 14-1.
Table 14-1.
JSpinner Properties
Property Name
Data Type
Access
accessibleContext
AccessibleContext
Read-only
changeListeners
ChangeListener[ ]
Read-only
editor
JComponent
Read-write bound
model
SpinnerModel
Read-write bound
nextValue
Object
Read-only
previousValue
Object
Read-only
UI
SpinnerUI
Read-write
UIClassID
String
Read-only
value
Object
Read-write