Question

I have a SpinnerNumberModel and some ChangeListeners.

But the ChangeListeners only get notified when the spinner number changes. Is there a way to initiate an event that propagates to the ChangeListeners even if the new spinner number is the same as the previous value?

Was it helpful?

Solution

SpinnerNumberModel sends an event to the registered change listeners in exactly these methods:

1. public void setValue(Object value)
2. public void setStepSize(Number stepSize)
3. public void setMaximum(Comparable maximum)
4. public void setMinimum(Comparable minimum)

In each of these methods, an event is only issued iff the value passed as the parameter actually differs from the current value.

However, you could write your own SpinnerModel (e.g. by subclassing SpinnerNumberModel) and fire all the events you want. If your implementation inherits from AbstractSpinnerModel, as SpinnerNumberModel does, you'll have a handy fireStateChanged method available for sending events:

http://download.oracle.com/javase/6/docs/api/javax/swing/AbstractSpinnerModel.html#fireStateChanged()

OTHER TIPS

Thomas beat me to it, but I came to the same conclusion and here's what I ended up doing:

private static class SpinnerNumberModel2 extends SpinnerNumberModel
{
    public SpinnerNumberModel2(int value, int minimum, int maximum, int stepSize)
    {
        super(value,minimum,maximum,stepSize);
    }
    public void fireUpdate() { super.fireStateChanged(); }
}   
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top