• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JSlider Change on Release

 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4632
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
put the code from changeListener into mouseReleased
 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good thinking, thanks
 
Brian Cole
Author
Ranch Hand
Posts: 899
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alter your ChangeListener to call the slider's getValueIsAdjusting() method and don't do anything intensive if the return value is true.
 
Jeff Storey
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian,

Even better - it doesn't involve moving code, thanks!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic