Cancelling the stateChanged for a slider

K

kmsterrett

Hello,
In the stateChanged event handling for a slider, if the JSliders value
exceeds a specified value,
I would like to reset it back to the specified value.

Is there some way to cancel the actionPerformed, and set the slider to
the maximumValue?

I cannot user slider.setMaximum to maximumValue, because through out
the program, the maximumValue can change and I do not want the ticks,
etc to change, just beacause I don't want the slider to go any higher.

I hope I have explained myself clearly.
Thanks for any help.
Kim


Here is my code, but the slider is not being set back to the maximum
value.
/** Listen to the slider. */
public void stateChanged(ChangeEvent e) {
JSlider source = (JSlider)e.getSource();
int fps = (int)source.getValue();


if (fps >= maximum{
source.setValue(maximumValue -1);
JOptionPane.showMessageDialog(null,"Start Frame cannot
be greater than End Frame." , "Error",
JOptionPane.ERROR_MESSAGE);
Toolkit.getDefaultToolkit().beep();
return;
}
else
System.out.println("Slider is now set to "+fps);

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top