aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Multiple sliders with a single listener - can it be done? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Multiple sliders with a single listener - can it be done?" Watch "Multiple sliders with a single listener - can it be done?" New topic
Author

Multiple sliders with a single listener - can it be done?

Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Can I have more than one JSlider reporting to a single ChangeListener, and be able to tell which one is triggering the event? If so, how? I currently have three sliders on my window and they are reporting to the same listener, but I can't seem to find out how to tell which one is being moved.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39886
    
  28
You can try the getSource() method if your Event has such a method.

But it sounds like a peculiar design to me.
Mike Lipay
Ranch Hand

Joined: Sep 11, 2007
Posts: 171
Ok. I knew you could identify buttons, wasn't sure if sliders worked the same, apparently not. I'll just create multiple listeners.
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39886
    
  28
The getSource() method appears to be inherited from EventObject, so you can probably find it.

But I suspect separate Listeners is a better solution.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Multiple sliders with a single listener - can it be done?