javax.swing

Class JSpinner

public class JSpinner extends JComponent

A JSpinner is a component that displays a single value from a sequence of values, and provides a convenient means for selecting the previous and next values in the sequence. Typically the spinner displays a numeric value, but it is possible to display dates or arbitrary items from a list.

Since: 1.4

Nested Class Summary
static classJSpinner.DateEditor
An editor class for a JSpinner that is used for displaying and editing dates (e.g. that uses SpinnerDateModel as model).
static classJSpinner.DefaultEditor
The base class for the editor used by the {@link JSpinner} component.
static classJSpinner.ListEditor
A JSpinner editor used for the {@link SpinnerListModel}.
static classJSpinner.NumberEditor
A panel containing a {@link JFormattedTextField} that is configured for displaying and editing numbers.
Constructor Summary
JSpinner()
Creates a new JSpinner with default instance of {@link SpinnerNumberModel} (that is, a model with value 0, step size 1, and no upper or lower limit).
JSpinner(SpinnerModel model)
Creates a new JSpinner with the specified model.
Method Summary
voidaddChangeListener(ChangeListener listener)
Adds a ChangeListener
voidcommitEdit()
If the editor is JSpinner.DefaultEditor, then forwards the call to it, otherwise do nothing.
protected JComponentcreateEditor(SpinnerModel model)
Creates an editor that is appropriate for the specified model.
protected voidfireStateChanged()
Fires a ChangeEvent to all the ChangeListeners added to this JSpinner
ChangeListener[]getChangeListeners()
Gets all the ChangeListeners
JComponentgetEditor()
Gets the current editor
SpinnerModelgetModel()
Returns the model used by the {@link JSpinner} component.
ObjectgetNextValue()
Gets the next value without changing the current value.
ObjectgetPreviousValue()
Gets the previous value without changing the current value.
SpinnerUIgetUI()
Gets the SpinnerUI that handles this spinner
StringgetUIClassID()
Returns the ID that identifies which look and feel class will be the UI delegate for this spinner.
ObjectgetValue()
Gets the current value of the spinner, according to the underly model, not the UI.
voidremoveChangeListener(ChangeListener listener)
Remove a particular listener
voidsetEditor(JComponent editor)
Changes the current editor to the new editor.
voidsetModel(SpinnerModel newModel)
Sets a new underlying model.
voidsetUI(SpinnerUI ui)
Sets the UI delegate for the component.
voidsetValue(Object value)
Sets the value in the model.
voidupdateUI()
This method resets the spinner's UI delegate to the default UI for the current look and feel.

Constructor Detail

JSpinner

public JSpinner()
Creates a new JSpinner with default instance of {@link SpinnerNumberModel} (that is, a model with value 0, step size 1, and no upper or lower limit).

See Also: SpinnerNumberModel

JSpinner

public JSpinner(SpinnerModel model)
Creates a new JSpinner with the specified model. The {@link #createEditor(SpinnerModel)} method is used to create an editor that is suitable for the model.

Parameters: model the model (null not permitted).

Throws: NullPointerException if model is null.

Method Detail

addChangeListener

public void addChangeListener(ChangeListener listener)
Adds a ChangeListener

Parameters: listener the listener to add

commitEdit

public void commitEdit()
If the editor is JSpinner.DefaultEditor, then forwards the call to it, otherwise do nothing.

Throws: ParseException DOCUMENT ME!

createEditor

protected JComponent createEditor(SpinnerModel model)
Creates an editor that is appropriate for the specified model.

Parameters: model the model.

Returns: The editor.

fireStateChanged

protected void fireStateChanged()
Fires a ChangeEvent to all the ChangeListeners added to this JSpinner

getChangeListeners

public ChangeListener[] getChangeListeners()
Gets all the ChangeListeners

Returns: all the ChangeListeners

getEditor

public JComponent getEditor()
Gets the current editor

Returns: the current editor

See Also: JSpinner

getModel

public SpinnerModel getModel()
Returns the model used by the {@link JSpinner} component.

Returns: The model.

See Also: setModel

getNextValue

public Object getNextValue()
Gets the next value without changing the current value.

Returns: the next value

See Also: SpinnerModel

getPreviousValue

public Object getPreviousValue()
Gets the previous value without changing the current value.

Returns: the previous value

See Also: SpinnerModel

getUI

public SpinnerUI getUI()
Gets the SpinnerUI that handles this spinner

Returns: the SpinnerUI

getUIClassID

public String getUIClassID()
Returns the ID that identifies which look and feel class will be the UI delegate for this spinner.

Returns: "SpinnerUI".

getValue

public Object getValue()
Gets the current value of the spinner, according to the underly model, not the UI.

Returns: the current value

See Also: SpinnerModel

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Remove a particular listener

Parameters: listener the listener to remove

setEditor

public void setEditor(JComponent editor)
Changes the current editor to the new editor. The old editor is removed from the spinner's {@link ChangeEvent} list.

Parameters: editor the new editor (null not permitted.

Throws: IllegalArgumentException if editor is null.

See Also: JSpinner

setModel

public void setModel(SpinnerModel newModel)
Sets a new underlying model.

Parameters: newModel the new model to set

Throws: IllegalArgumentException if newModel is null

setUI

public void setUI(SpinnerUI ui)
Sets the UI delegate for the component.

Parameters: ui The spinner's UI delegate.

setValue

public void setValue(Object value)
Sets the value in the model.

Parameters: value the new value.

updateUI

public void updateUI()
This method resets the spinner's UI delegate to the default UI for the current look and feel.