|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--JSpinner
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 JSpinners 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 ChangeEvent
s.
By default the editor is a JFormattedTextField
and it's
configured to suit the SpinnerModel.
SpinnerModel
,
AbstractSpinnerModel
,
SpinnerListModel
,
SpinnerNumberModel
,
SpinnerDateModel
,
JFormattedTextField
, Serialized FormInner classes inherited from class javax.swing.JComponent |
javax.swing.JComponent.AccessibleJComponent |
Inner classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
Inner classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent |
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()
Construct a spinner with an Integer SpinnerNumberModel with initial value 0 and no minimum or maximum limits. |
|
JSpinner(SpinnerModel model)
Construct a complete spinner with pair of next/previous buttons and an editor for the SpinnerModel. |
Method Summary | |
protected javax.swing.JComponent |
createEditor(SpinnerModel model)
This method is called by the constructors to create the JComponent that displays the current value of the sequence. |
javax.swing.JComponent |
getEditor()
Returns the component that displays and potentally changes the models value. |
SpinnerModel |
getModel()
Returns the SpinnerModel that defines this spinners sequence of values. |
SpinnerUI |
getUI()
Returns the look and feel (L&F) object that renders this component. |
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. |
void |
setEditor(javax.swing.JComponent editor)
Change 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 |
updateUI()
Resets the UI property with the value from the current look and feel. |
Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree |
Methods inherited from class java.awt.Component |
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public JSpinner(SpinnerModel model)
public JSpinner()
Method Detail |
public SpinnerUI getUI()
public void setUI(SpinnerUI ui)
ui
- the ListUI L&F objectUIDefaults#getUI
public java.lang.String getUIClassID()
getUIClassID
in class javax.swing.JComponent
JComponent.getUIClassID()
,
UIDefaults#getUI
public void updateUI()
updateUI
in class javax.swing.JComponent
UIManager#getUI
protected javax.swing.JComponent createEditor(SpinnerModel model)
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.
model
- the value of getModelgetModel()
,
setEditor(javax.swing.JComponent)
public void setModel(SpinnerModel model)
ChangeListener
from
the old model and adding it to the new one, and then forcing
the editor to update (repaint, revalidate
).model
- the new SpinnerModeljava.lang.IllegalArgumentException
- if model is nullgetModel()
,
getEditor()
public SpinnerModel getModel()
setModel(SpinnerModel)
public void setEditor(javax.swing.JComponent editor)
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 and adding one for
the new editor.editor
- the new editorjava.lang.IllegalArgumentException
- if editor is nullgetEditor()
,
createEditor(SpinnerModel)
,
getModel()
public javax.swing.JComponent getEditor()
setEditor(javax.swing.JComponent)
,
createEditor(SpinnerModel)
|
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |