How to check if a value was set manually, and not with setValue (JSlider, JSpinner)?

How to check if a JSlider or JSpinner value is set via the graphical interface, and not through the setValue( int n) method?

+6
source share
2 answers

Set the boolean value true when you call setValue programmatically (before calling it) and reset to false when you finish processing the event.

+5
source

Inside, the setValue method is called. You can try to catch an event when the user moves the handle of the slider by implementing ChangeListener to capture this event. Also, remember that moving the handle causes a lot of event changes, so if you are interested in the final value of the slider, use getValueIsAdjusting when it evaluates to false .


If the problem is related to ChangeListener , try extending the JSlider component and add a new method that gets a new AND value that returns it (for example, using int code or an enumeration), getting the value set up after you create your own logic for the real method setValue.

In your case, you want to prevent invokation setValue if some component calls it, if I'm not mistaken.

+1
source

All Articles