Methods Summary |
---|
public void | addChangeListener(javax.swing.event.ChangeListener listener)Adds a listener to the list that is notified each time a change
to the model occurs. The source of ChangeEvents
delivered to ChangeListeners will be this
JSpinner . Note also that replacing the model
will not affect listeners added directly to JSpinner.
Applications can add listeners to the model directly. In that
case is that the source of the event would be the
SpinnerModel .
if (modelListener == null) {
modelListener = new ModelListener();
getModel().addChangeListener(modelListener);
}
listenerList.add(ChangeListener.class, listener);
|
public void | commitEdit()Commits the currently edited value to the SpinnerModel .
If the editor is an instance of DefaultEditor , the
call if forwarded to the editor, otherwise this does nothing.
JComponent editor = getEditor();
if (editor instanceof DefaultEditor) {
((DefaultEditor)editor).commitEdit();
}
|
protected javax.swing.JComponent | createEditor(javax.swing.SpinnerModel model)This method is called by the constructors to create the
JComponent
that displays the current value of the sequence. The editor may
also allow the user to enter an element of the sequence directly.
An editor must listen for ChangeEvents on the
model and keep the value it displays
in sync with the value of the model.
Subclasses may override this method to add support for new
SpinnerModel classes. Alternatively one can just
replace the editor created here with the setEditor
method. The default mapping from model type to editor is:
-
SpinnerNumberModel => JSpinner.NumberEditor
-
SpinnerDateModel => JSpinner.DateEditor
-
SpinnerListModel => JSpinner.ListEditor
- all others =>
JSpinner.DefaultEditor
if (model instanceof SpinnerDateModel) {
return new DateEditor(this);
}
else if (model instanceof SpinnerListModel) {
return new ListEditor(this);
}
else if (model instanceof SpinnerNumberModel) {
return new NumberEditor(this);
}
else {
return new DefaultEditor(this);
}
|
protected void | fireStateChanged()Sends a ChangeEvent , whose source is this
JSpinner , to each ChangeListener .
When a ChangeListener has been added
to the spinner, this method method is called each time
a ChangeEvent is received from the model.
Object[] listeners = listenerList.getListenerList();
for (int i = listeners.length - 2; i >= 0; i -= 2) {
if (listeners[i] == ChangeListener.class) {
if (changeEvent == null) {
changeEvent = new ChangeEvent(this);
}
((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
}
}
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext for the JSpinner
if (accessibleContext == null) {
accessibleContext = new AccessibleJSpinner();
}
return accessibleContext;
|
public javax.swing.event.ChangeListener[] | getChangeListeners()Returns an array of all the ChangeListener s added
to this JSpinner with addChangeListener().
return (ChangeListener[])listenerList.getListeners(
ChangeListener.class);
|
public javax.swing.JComponent | getEditor()Returns the component that displays and potentially
changes the model's value.
return editor;
|
public javax.swing.SpinnerModel | getModel()Returns the SpinnerModel that defines
this spinners sequence of values.
return model;
|
public java.lang.Object | getNextValue()Returns the object in the sequence that comes after the object returned
by getValue() . If the end of the sequence has been reached
then return null .
Calling this method does not effect value .
This method simply delegates to the model .
It is equivalent to:
getModel().getNextValue()
return getModel().getNextValue();
|
public java.lang.Object | getPreviousValue()Returns the object in the sequence that comes
before the object returned by getValue() .
If the end of the sequence has been reached then
return null . Calling this method does
not effect value .
This method simply delegates to the model .
It is equivalent to:
getModel().getPreviousValue()
return getModel().getPreviousValue();
|
public javax.swing.plaf.SpinnerUI | getUI()Returns the look and feel (L&F) object that renders this component.
return (SpinnerUI)ui;
|
public java.lang.String | getUIClassID()Returns the suffix used to construct the name of the look and feel
(L&F) class used to render this component.
return uiClassID;
|
public java.lang.Object | getValue()Returns the current value of the model, typically
this value is displayed by the editor . If the
user has changed the value displayed by the editor it is
possible for the model 's value to differ from that of
the editor , refer to the class level javadoc for examples
of how to deal with this.
This method simply delegates to the model .
It is equivalent to:
getModel().getValue()
return getModel().getValue();
|
private void | readObject(java.io.ObjectInputStream s)
s.defaultReadObject();
Map additionalValues = (Map)s.readObject();
model = (SpinnerModel)additionalValues.get("model");
|
public void | removeChangeListener(javax.swing.event.ChangeListener listener)Removes a ChangeListener from this spinner.
listenerList.remove(ChangeListener.class, listener);
|
public void | setEditor(javax.swing.JComponent editor)Changes the JComponent that displays the current value
of the SpinnerModel . It is the responsibility of this
method to disconnect the old editor from the model and to
connect the new editor. This may mean removing the
old editors ChangeListener from the model or the
spinner itself and adding one for the new editor.
if (editor == null) {
throw new IllegalArgumentException("null editor");
}
if (!editor.equals(this.editor)) {
JComponent oldEditor = this.editor;
this.editor = editor;
if (oldEditor instanceof DefaultEditor) {
((DefaultEditor)oldEditor).dismiss(this);
}
editorExplicitlySet = true;
firePropertyChange("editor", oldEditor, editor);
revalidate();
repaint();
}
|
public void | setModel(javax.swing.SpinnerModel model)Changes the model that represents the value of this spinner.
If the editor property has not been explicitly set,
the editor property is (implicitly) set after the "model"
PropertyChangeEvent has been fired. The editor
property is set to the value returned by createEditor ,
as in:
setEditor(createEditor(model));
if (model == null) {
throw new IllegalArgumentException("null model");
}
if (!model.equals(this.model)) {
SpinnerModel oldModel = this.model;
this.model = model;
if (modelListener != null) {
this.model.addChangeListener(modelListener);
}
firePropertyChange("model", oldModel, model);
if (!editorExplicitlySet) {
setEditor(createEditor(model)); // sets editorExplicitlySet true
editorExplicitlySet = false;
}
repaint();
revalidate();
}
|
public void | setUI(javax.swing.plaf.SpinnerUI ui)Sets the look and feel (L&F) object that renders this component.
super.setUI(ui);
|
public void | setValue(java.lang.Object value)Changes current value of the model, typically
this value is displayed by the editor .
If the SpinnerModel implementation
doesn't support the specified value then an
IllegalArgumentException is thrown.
This method simply delegates to the model .
It is equivalent to:
getModel().setValue(value)
getModel().setValue(value);
|
public void | updateUI()Resets the UI property with the value from the current look and feel.
setUI((SpinnerUI)UIManager.getUI(this));
invalidate();
|
private void | writeObject(java.io.ObjectOutputStream s)
s.defaultWriteObject();
HashMap additionalValues = new HashMap(1);
SpinnerModel model = getModel();
if (model instanceof Serializable) {
additionalValues.put("model", model);
}
s.writeObject(additionalValues);
if (getUIClassID().equals(uiClassID)) {
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, --count);
if (count == 0 && ui != null) {
ui.installUI(this);
}
}
|