source = (JSlider)evt.getSource() ; if ( !source.getValueIsAdjusting() ) { if ( source.getName()().equals("sliderA") ) textA.setText( source.getValue() + " " ); if ( source.getName()().equals("sliderB") ) textB.setText( source.getValue() + " " ); }
For fun, modify the previous program to see the result of this patch.
Here are a few other sometimes useful methods from
class JSlider
.
For additional discussion go to
How to Use Sliders in Sun's on-line Java Tutorial.
int getMaximum() // Returns the maximum value supported by the slider.
int getMinimum() // Returns the minimum value supported by the slider.
These two methods are useful when the application methods must scale their output proportional to the possible range of values.
void setInverted(boolean b) //Set to true to reverse the order of values on the slider
This method with a horizontal slider makes the values ascend going from right to left (the revers of the usual order).
Is it possible to disable a slider?