java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JSpinner
public class 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 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. 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. To make sure the model has the same
value as the editor use the commitEdit method, eg:
try { spinner.commitEdit(); } // Edited value is invalid, spinner.getValue() will return // the last valid value, you could revert the spinner to show that: if (editor instanceof DefaultEditor) { ((DefaultEditor)editor).getTextField().setValue(spinner.getValue(); } // reset the value to some known value: spinner.setValue(fallbackValue); // or treat the last valid value as the current, in which // case you don't need to do anything. } return spinner.getValue();
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.
SpinnerModel,
AbstractSpinnerModel,
SpinnerListModel,
SpinnerNumberModel,
SpinnerDateModel,
JFormattedTextField| Nested Class Summary | |
|---|---|
protected class |
JSpinner.AccessibleJSpinner
AccessibleJSpinner implements accessibility
support for the JSpinner class. |
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/interfaces inherited from class javax.swing.JComponent |
|---|
JComponent.AccessibleJComponent |
| Nested classes/interfaces inherited from class java.awt.Container |
|---|
Container.AccessibleAWTContainer |
| Nested classes/interfaces 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. |
AccessibleContext |
getAccessibleContext()
Gets the AccessibleContext |
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. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Constructor Detail |
|---|
public JSpinner(SpinnerModel model)
SpinnerModel.
public JSpinner()
Integer SpinnerNumberModel
with initial value 0 and no minimum or maximum limits.
| Method Detail |
|---|
public SpinnerUI getUI()
SpinnerUI object that renders this componentpublic void setUI(SpinnerUI ui)
ui - the SpinnerUI L&F objectUIDefaults.getUI(javax.swing.JComponent)public String getUIClassID()
getUIClassID in class JComponentJComponent.getUIClassID(),
UIDefaults.getUI(javax.swing.JComponent)public void updateUI()
updateUI in class JComponentprotected JComponent createEditor(SpinnerModel model)
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
JSpinner.DefaultEditor
model - the value of getModel
getModel(),
setEditor(javax.swing.JComponent)public void setModel(SpinnerModel model)
"model"
PropertyChangeEvent has been fired. The editor
property is set to the value returned by createEditor,
as in:
setEditor(createEditor(model));
model - the new SpinnerModel
IllegalArgumentException - if model is nullgetModel(),
getEditor(),
setEditor(javax.swing.JComponent)public SpinnerModel getModel()
SpinnerModel that defines
this spinners sequence of values.
setModel(javax.swing.SpinnerModel)public Object getValue()
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()
public void setValue(Object value)
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)
IllegalArgumentException - if value isn't allowedgetValue(),
SpinnerModel.setValue(java.lang.Object)public Object getNextValue()
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()
null if one doesn't existgetValue(),
getPreviousValue(),
SpinnerModel.getNextValue()public void addChangeListener(ChangeListener listener)
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.
listener - the ChangeListener to addremoveChangeListener(javax.swing.event.ChangeListener),
getModel()public void removeChangeListener(ChangeListener listener)
ChangeListener from this spinner.
listener - the ChangeListener to removefireStateChanged(),
addChangeListener(javax.swing.event.ChangeListener)public ChangeListener[] getChangeListeners()
ChangeListeners added
to this JSpinner with addChangeListener().
ChangeListeners added or an empty
array if no listeners have been addedprotected void fireStateChanged()
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.
public Object getPreviousValue()
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()
null
if one doesn't existgetValue(),
getNextValue(),
SpinnerModel.getPreviousValue()public void setEditor(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 or the
spinner itself and adding one for the new editor.
editor - the new editor
IllegalArgumentException - if editor is nullgetEditor(),
createEditor(javax.swing.SpinnerModel),
getModel()public JComponent getEditor()
setEditor(javax.swing.JComponent),
createEditor(javax.swing.SpinnerModel)
public void commitEdit()
throws ParseException
SpinnerModel.
If the editor is an instance of DefaultEditor, the
call if forwarded to the editor, otherwise this does nothing.
ParseException - if the currently edited value couldn't
be commited.public AccessibleContext getAccessibleContext()
AccessibleContext for the JSpinner
getAccessibleContext in interface AccessiblegetAccessibleContext in class JComponentAccessibleContext for the JSpinnerCes informations proviennent du site de http://java.sun.com
Le contenu de cette page provient du site de Sun, et est généré depuis un cache sur l'infobrol après certains traitements automatisés. La présentation peut donc différer du document original, mais le contenu aussi. Vous pouvez utiliser ce bouton pour afficher la page originale du site de Sun :
Maintenir les pages en cache sur différents sites peut offrir plus de disponibilité.
Chaque page est indexée dans la base de donnée, ce qui permet de retrouver facilement les informations, au moyen des sommaires, du moteur de recherche interne, etc.
Des facilités sont mises en place pour que les membres de l'infobrol puissent effectuer des traductions en français des différents documents. Ceci devrait permettre aux débutants en programmation Java de consulter les API en français s'ils maîtrisent moins bien la langue de Shakespeare. Dans le cas où une traduction a été soumise, elle est disponible au moyen d'un lien en bas de page. Si la traduction a été validée, la page s'affiche par défaut en français, et un lien en bas de page permet d'atteindre la version en anglais.
Le code sur l'infobrol est automatiquement coloré selon la syntaxe, et les différents mots clés sont transformés en liens pour accéder rapidement aux informations.
Vous avez la possibilité de partager vos expériences en proposant vos propres extraits de code en utilisant le bouton "ajouter un commentaire" en bas de page. Si vous visitez simplement l'infobrol, vous avez déjà accès à cette fonction, mais si vous étes membre du brol, vous pouvez en plus utiliser des boutons supplémentaires de mise en forme, dont la coloration automatique de vos extraits de codes.
Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher les interactions avec les réseaux sociaux sur ces pages.
6 mots clés dont 0 définis manuellement (plus d'information...).
Avertissement
Cette page ne possède pas encore de mots clés manuels, ceci est donc un exemple automatique (les niveaux de pertinence sont fictifs, mais les liens sont valables). Pour tester le nuage avec une page qui contient des mots définis manuellement, vous pouvez cliquer ici.Vous pouvez modifier vos préférences dans votre profil pour ne plus afficher le nuage de mots clés.
Recherche (afficher)
Utilisateur (masquer)
Navigation (masquer)
Apparence (afficher)
Stats (afficher)
Citation (masquer)