Question

How can I check if the value of a JSlider or JSpinner was set via the graphical interface and not via the method setValue( int n) ?

Was it helpful?

Solution

Set a boolean value to true whenever you call setValue programmatically (before calling it), and reset it to false when you are done with the event handling.

OTHER TIPS

Internally, ´setValue´ is invoked. You can try catching the event when the user moves the knob of the slider by implementing a ChangeListener to capture that event. Plus, remember that moving the knob triggers many change events, so if you're interested on the final value of the slider, make use of the getValueIsAdjusting when it evaluates to false.


If the problem is withing a ChangeListener, try extending the JSlider component and add a new method that receives the new value AND who issues it (with an int code or an enum, for example), deriving the setting of the value after you make your custom logic to the real setValue method.

In your case, you'll want to prevent the invokation of setValue if certain component invokes it, if I'm not mistaken.

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