public class

BasicSpinnerUI

extends SpinnerUI
java.lang.Object
   ↳ javax.swing.plaf.ComponentUI
     ↳ javax.swing.plaf.SpinnerUI
       ↳ javax.swing.plaf.basic.BasicSpinnerUI
Known Direct Subclasses

Class Overview

The default Spinner UI delegate.

Summary

Fields
protected JSpinner spinner The spinner that we're a UI delegate for.
Public Constructors
BasicSpinnerUI()
Public Methods
static ComponentUI createUI(JComponent c)
Returns a new instance of BasicSpinnerUI.
int getBaseline(JComponent c, int width, int height)
Returns the baseline.
Component.BaselineResizeBehavior getBaselineResizeBehavior(JComponent c)
Returns an enum indicating how the baseline of the component changes as the size changes.
void installUI(JComponent c)
Calls installDefaults, installListeners, and then adds the components returned by createNextButton, createPreviousButton, and createEditor.
void uninstallUI(JComponent c)
Calls uninstallDefaults, uninstallListeners, and then removes all of the spinners children.
Protected Methods
JComponent createEditor()
This method is called by installUI to get the editor component of the JSpinner.
LayoutManager createLayout()
Create a LayoutManager that manages the editor, nextButton, and previousButton children of the JSpinner.
Component createNextButton()
Create a component that will replace the spinner models value with the object returned by spinner.getNextValue.
Component createPreviousButton()
Create a component that will replace the spinner models value with the object returned by spinner.getPreviousValue.
PropertyChangeListener createPropertyChangeListener()
Create a PropertyChangeListener that can be added to the JSpinner itself.
void installDefaults()
Initialize the JSpinner border, foreground, and background, properties based on the corresponding "Spinner.*" properties from defaults table.
void installKeyboardActions()
Installs the keyboard Actions onto the JSpinner.
void installListeners()
Initializes PropertyChangeListener with a shared object that delegates interesting PropertyChangeEvents to protected methods.
void installNextButtonListeners(Component c)
Installs the necessary listeners on the next button, c, to update the JSpinner in response to a user gesture.
void installPreviousButtonListeners(Component c)
Installs the necessary listeners on the previous button, c, to update the JSpinner in response to a user gesture.
void replaceEditor(JComponent oldEditor, JComponent newEditor)
Called by the PropertyChangeListener when the JSpinner editor property changes.
void uninstallDefaults()
Sets the JSpinner's layout manager to null.
void uninstallListeners()
Removes the PropertyChangeListener added by installListeners.
[Expand]
Inherited Methods
From class javax.swing.plaf.ComponentUI
From class java.lang.Object

Fields

protected JSpinner spinner

The spinner that we're a UI delegate for. Initialized by the installUI method, and reset to null by uninstallUI.

Public Constructors

public BasicSpinnerUI ()

Public Methods

public static ComponentUI createUI (JComponent c)

Returns a new instance of BasicSpinnerUI. SpinnerListUI delegates are allocated one per JSpinner.

Parameters
c the JSpinner (not used)
Returns
  • a new BasicSpinnerUI object

public int getBaseline (JComponent c, int width, int height)

Returns the baseline.

Parameters
c JComponent baseline is being requested for
width the width to get the baseline for
height the height to get the baseline for
Returns
  • baseline or a value < 0 indicating there is no reasonable baseline

public Component.BaselineResizeBehavior getBaselineResizeBehavior (JComponent c)

Returns an enum indicating how the baseline of the component changes as the size changes.

Parameters
c JComponent to return baseline resize behavior for
Returns
  • an enum indicating how the baseline changes as the component size changes

public void installUI (JComponent c)

Calls installDefaults, installListeners, and then adds the components returned by createNextButton, createPreviousButton, and createEditor.

Parameters
c the JSpinner

public void uninstallUI (JComponent c)

Calls uninstallDefaults, uninstallListeners, and then removes all of the spinners children.

Parameters
c the JSpinner (not used)

Protected Methods

protected JComponent createEditor ()

This method is called by installUI to get the editor component of the JSpinner. By default it just returns JSpinner.getEditor(). Subclasses can override createEditor to return a component that contains the spinner's editor or null, if they're going to handle adding the editor to the JSpinner in an installUI override.

Typically this method would be overridden to wrap the editor with a container with a custom border, since one can't assume that the editors border can be set directly.

The replaceEditor method is called when the spinners editor is changed with JSpinner.setEditor. If you've overriden this method, then you'll probably want to override replaceEditor as well.

Returns
  • the JSpinners editor JComponent, spinner.getEditor() by default

protected LayoutManager createLayout ()

Create a LayoutManager that manages the editor, nextButton, and previousButton children of the JSpinner. These three children must be added with a constraint that identifies their role: "Editor", "Next", and "Previous". The default layout manager can handle the absence of any of these children.

Returns
  • a LayoutManager for the editor, next button, and previous button.

protected Component createNextButton ()

Create a component that will replace the spinner models value with the object returned by spinner.getNextValue. By default the nextButton is a JButton who's ActionListener updates it's JSpinner ancestors model. If a nextButton isn't needed (in a subclass) then override this method to return null.

Returns
  • a component that will replace the spinners model with the next value in the sequence, or null

protected Component createPreviousButton ()

Create a component that will replace the spinner models value with the object returned by spinner.getPreviousValue. By default the previousButton is a JButton. This method invokes installPreviousButtonListeners to install the necessary listeners to update the JSpinner's model in response to a user gesture. If a previousButton isn't needed (in a subclass) then override this method to return null.

Returns
  • a component that will replace the spinners model with the next value in the sequence, or null

protected PropertyChangeListener createPropertyChangeListener ()

Create a PropertyChangeListener that can be added to the JSpinner itself. Typically, this listener will call replaceEditor when the "editor" property changes, since it's the SpinnerUI's responsibility to add the editor to the JSpinner (and remove the old one). This method is called by installListeners.

Returns
  • A PropertyChangeListener for the JSpinner itself

protected void installDefaults ()

Initialize the JSpinner border, foreground, and background, properties based on the corresponding "Spinner.*" properties from defaults table. The JSpinners layout is set to the value returned by createLayout. This method is called by installUI.

protected void installKeyboardActions ()

Installs the keyboard Actions onto the JSpinner.

protected void installListeners ()

Initializes PropertyChangeListener with a shared object that delegates interesting PropertyChangeEvents to protected methods.

This method is called by installUI.

protected void installNextButtonListeners (Component c)

Installs the necessary listeners on the next button, c, to update the JSpinner in response to a user gesture.

Parameters
c Component to install the listeners on
Throws
NullPointerException if c is null.

protected void installPreviousButtonListeners (Component c)

Installs the necessary listeners on the previous button, c, to update the JSpinner in response to a user gesture.

Parameters
c Component to install the listeners on.
Throws
NullPointerException if c is null.

protected void replaceEditor (JComponent oldEditor, JComponent newEditor)

Called by the PropertyChangeListener when the JSpinner editor property changes. It's the responsibility of this method to remove the old editor and add the new one. By default this operation is just:

 spinner.remove(oldEditor);
 spinner.add(newEditor, "Editor");
 
The implementation of replaceEditor should be coordinated with the createEditor method.

protected void uninstallDefaults ()

Sets the JSpinner's layout manager to null. This method is called by uninstallUI.

protected void uninstallListeners ()

Removes the PropertyChangeListener added by installListeners.

This method is called by uninstallUI.