javax.swing

Interface SpinnerModel

public interface SpinnerModel

The data model that is used in {@link JSpinner}s.

Since: 1.4

Method Summary
voidaddChangeListener(ChangeListener listener)
Adds a ChangeListener to the list of registered listeners.
ObjectgetNextValue()
Returns the next value from the model.
ObjectgetPreviousValue()
Returns the previous value from the model.
ObjectgetValue()
Returns the current value of the model.
voidremoveChangeListener(ChangeListener listener)
Removes a given ChangeListener from the list of registered listeners.
voidsetValue(Object value)
Sets the current value of the model to that specified.

Method Detail

addChangeListener

public void addChangeListener(ChangeListener listener)
Adds a ChangeListener to the list of registered listeners. Each listener is notified when the current value is changed.

Parameters: listener The new listener to register.

getNextValue

public Object getNextValue()
Returns the next value from the model. If the model is bounded, this method may return null when the upper bound is met. The current value is not changed.

Returns: The next value, or null if there are no more values to retrieve.

getPreviousValue

public Object getPreviousValue()
Returns the previous value from the model. If the model is bounded, this method may return null when the lower bound is met. The current value is not changed.

Returns: The previous value, or null if there are no more values to retrieve.

getValue

public Object getValue()
Returns the current value of the model.

Returns: The current value.

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Removes a given ChangeListener from the list of registered listeners.

Parameters: listener The listener to remove.

setValue

public void setValue(Object value)
Sets the current value of the model to that specified. Implementations can choose to refuse to accept the value and throw an exception instead. For example, a date model may throw invalid dates, or a list model may throw out values which don't exist in the underlying list. Models may also throw out unusual values, such as null. The decision is left to the discretion of the implementator. If the operation succeeds, the implementation should also notify any registered ChangeListeners.

Parameters: value The new value of the model.

Throws: IllegalArgumentException if the model does not accept the given value.