javax.swing
Class JSpinnerjava.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--javax.swing.JSpinner
- All Implemented Interfaces:
- ImageObserver, MenuContainer, Serializable
- public class JSpinner
- extends JComponent
A single line input field that lets the user select a number or an object value from an ordered sequence. Spinners typically provide a pair of tiny arrow buttons for stepping through the elements of the sequence. The keyboard up/down arrow keys also cycle through the elements. The user may also be allowed to type a (legal) value directly into the spinner. Although combo boxes provide similar functionality, spinners are sometimes preferred because they don't require a drop down list that can obscure important data.
A JSpinner's sequence value is defined by its SpinnerModel. The model can be specified as a constructor argument and changed with the model property. SpinnerModel classes for some common types are provided: SpinnerListModel, SpinnerNumberModel, and SpinnerDateModel.
A JSpinner has a single child component that's responsible for displaying and potentially changing the current element or value of the model, which is called the editor. The editor is created by the JSpinner's constructor and can be changed with the editor property. The JSpinner's editor stays in sync with the model by listening for ChangeEvents.
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing. As of 1.4, support for long term storage of all JavaBeansTM has been added to the java.beans package. Please see XMLEncoder.
- Since:
- 1.4
- See Also:
- SpinnerModel, AbstractSpinnerModel, SpinnerListModel, SpinnerNumberModel, SpinnerDateModel, JFormattedTextField
Nested Class Summary
static class JSpinner.DateEditor
An editor for a JSpinner whose model is a SpinnerDateModel.static class JSpinner.DefaultEditor
A simple base class for more specialized editors that displays a read-only view of the model's current value with a JFormattedTextField.static class JSpinner.ListEditor
An editor for a JSpinner whose model is a SpinnerListModel.static class JSpinner.NumberEditor
An editor for a JSpinner whose model is a SpinnerNumberModel.
Nested classes inherited from class javax.swing.JComponent JComponent.AccessibleJComponent
Nested classes inherited from class java.awt.Container Container.AccessibleAWTContainer
Nested classes inherited from class java.awt.Component Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
Field Summary
Fields inherited from class javax.swing.JComponent accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Fields inherited from class java.awt.Component BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
Fields inherited from interface java.awt.image.ImageObserver ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Constructor Summary
JSpinner()
Constructs a spinner with an Integer SpinnerNumberModel with initial value 0 and no minimum or maximum limits.JSpinner(SpinnerModel model)
Constructs a complete spinner with pair of next/previous buttons and an editor for the SpinnerModel.
Method Summary
void addChangeListener(ChangeListener listener)
Adds a listener to the list that is notified each time a change to the model occurs.void commitEdit()
Commits the currently edited value to the SpinnerModel.protected JComponent createEditor(SpinnerModel model)
This method is called by the constructors to create the JComponent that displays the current value of the sequence.protected void fireStateChanged()
Sends a ChangeEvent, whose source is this JSpinner, to each ChangeListener.ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListeners added to this JSpinner with addChangeListener().JComponent getEditor()
Returns the component that displays and potentially changes the model's value.SpinnerModel getModel()
Returns the SpinnerModel that defines this spinners sequence of values.Object getNextValue()
Returns the object in the sequence that comes after the object returned by getValue().Object getPreviousValue()
Returns the object in the sequence that comes before the object returned by getValue().SpinnerUI getUI()
Returns the look and feel (L&F) object that renders this component.String getUIClassID()
Returns the suffix used to construct the name of the look and feel (L&F) class used to render this component.Object getValue()
Returns the current value of the model, typically this value is displayed by the editor.void removeChangeListener(ChangeListener listener)
Removes a ChangeListener from this spinner.void setEditor(JComponent editor)
Changes the JComponent that displays the current value of the SpinnerModel.void setModel(SpinnerModel model)
Changes the model that represents the value of this spinner.void setUI(SpinnerUI ui)
Sets the look and feel (L&F) object that renders this component.void setValue(Object value)
Changes current value of the model, typically this value is displayed by the editor.void updateUI()
Resets the UI property with the value from the current look and feel.