Question

How can I programmatically fire the change listener of a JSlider?

Was it helpful?

Solution

Assuming you want to notify listeners of the slider, you would use this:

    ChangeEvent ce = new ChangeEvent(slider);
    for(ChangeListener cl : slider.getChangeListeners()){
        cl.stateChanged(ce);
    }

You shouldn't need to fire the change event directly unless you're extending the class and adding some new funky functionality. In that case, the fireStateChanged() method is protected, so you should have access.

OTHER TIPS

slider.setValue(value) will fire a state changed event.

have look at ChangeListener, examples here and here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top