Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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) ?

like image 771
andreihondrari Avatar asked Jan 14 '13 14:01

andreihondrari


2 Answers

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.

like image 142
lbalazscs Avatar answered Nov 16 '22 04:11

lbalazscs


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.

like image 40
Fritz Avatar answered Nov 16 '22 05:11

Fritz