Rendicahya
Rendicahya

Reputation: 4285

How to fire JSlider change listener?

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

Upvotes: 1

Views: 2563

Answers (3)

Eva
Eva

Reputation: 4690

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

Upvotes: 0

Ami
Ami

Reputation: 4259

have look at ChangeListener, examples here and here

Upvotes: -1

Nick Rippe
Nick Rippe

Reputation: 6465

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.

Upvotes: 7

Related Questions