I am using a JSlider in my program, and have implemented a ChangeListener for the same.
public void stateChanged(ChangeEvent e)
{
JSlider source=(JSlider) e.getSource();
frame_value.setText(Integer.toString(source.getValue()));
//Condition to change the frame_no only when user has stopped moving the slider
if (!source.getValueIsAdjusting())
{
frame_no=(int) source.getValue()-1;
if(frame_no<0)
frame_no=0;
}
....
}
What is happening is, that whenever the ChangeListener is called, the program just skips the if block, and goes to the code after that. I don't understand why is this happening. I am not able to get the correct value from the JSlider. Please help!!
PS: I don't know if this is the reason, but recently I have set the UI of the JSlider to place the tick where I click it. I don't know if that is responsible for it or not. Here is the code:
slider.setUI(new MetalSliderUI() {
protected void scrollDueToClickInTrack(int direction) {
int value = HEVC_Analyzer.slider.getValue();
value = this.valueForXPosition(HEVC_Analyzer.slider.getMousePosition().x);
HEVC_Analyzer.slider.setValue(value);
}
});