How to fire JSlider change listener?
-
07-07-2021 - |
Question
How can I programmatically fire the change listener of a JSlider
?
La 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.
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow