Two Laptop Bag*
The moose likes Swing / AWT / SWT and the fly likes JSlider Change on Release Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "JSlider Change on Release" Watch "JSlider Change on Release" New topic
Author

JSlider Change on Release

Jeff Storey
Ranch Hand

Joined: Oct 09, 2006
Posts: 118
Hi. Is there any easy way to make a JSlider fire its change listener when the slider is released by the user, rather than being fired each time the value changes during the dragging. I have a JSlider, that when changed, performs some visual tweaking of an image based on the position of the slider. This can sometimes be an intense process, so if the user is dragging the slider bar a long way, I don't want it fired at each step.

My thought was to add a mouse listener that detects when the mouse is pressed and when it is released. Anytime in between it tells the change listener to do nothing. Any other thoughts?

Thanks,
Jeff
Michael Dunn
Ranch Hand

Joined: Jun 09, 2003
Posts: 4632
put the code from changeListener into mouseReleased
Jeff Storey
Ranch Hand

Joined: Oct 09, 2006
Posts: 118
good thinking, thanks
Brian Cole
Author
Ranch Hand

Joined: Sep 20, 2005
Posts: 862
Alter your ChangeListener to call the slider's getValueIsAdjusting() method and don't do anything intensive if the return value is true.


bitguru blog
Jeff Storey
Ranch Hand

Joined: Oct 09, 2006
Posts: 118
Brian,

Even better - it doesn't involve moving code, thanks!
 
Don't get me started about those stupid light bulbs.
 
subject: JSlider Change on Release