Skip to main content



      Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Removing listeners from Scrollbar [solved](Trying to remove mouse wheel listener(s) from scrollbar as mousewheel is being used elsewhere)
Removing listeners from Scrollbar [solved] [message #686075] Tue, 21 June 2011 11:33 Go to next message
Eclipse UserFriend
Hey,

I have a view created using SWT, including the scrollbars. I've just added listeners to the canvas, including a MouseWheelListener to zoom in and out of the image on the canvas. However, when I do this the scrollbar (when present) also reacts to the mousewheel, scrolling the image up or down in addition to zooming.

I presume that I need to use scrollbar.removeListener() in some way, but I can't figure out how. Using scrollbar.getListeners(x), where x is SWT.MouseWheel or SWT.MouseVerticalWheel also doesn't appear to give anything useful. Any advice?

A snippet of the code:
private void initScrollBars() {
		ScrollBar horizontal = getHorizontalBar();
		horizontal.setEnabled(false);
		horizontal.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(SelectionEvent event) {
				scrollHorizontally((ScrollBar) event.widget);
			}
		});
	// similar code for vertical scrollbar
	}
//canvas.addMouseWheelListener(new MouseWheelListener() is used in other class


Thanks! George

[Updated on: Wed, 22 June 2011 10:40] by Moderator

Re: Removing listeners from Scrollbar [message #686521 is a reply to message #686075] Wed, 22 June 2011 08:20 Go to previous messageGo to next message
Eclipse UserFriend
Hi,

In the example, the Canvas receives the SWT.MouseWheel events. You can try to prevent the default scrolling by setting the event.doit = false in the event listener.

canvas.addListener(SWT.MouseWheel, new Listener() {
public void handleEvent(Event event) {
event.doit = false;

//do something
}
});

[Updated on: Wed, 22 June 2011 08:21] by Moderator

Re: Removing listeners from Scrollbar [message #686560 is a reply to message #686521] Wed, 22 June 2011 09:48 Go to previous message
Eclipse UserFriend
That's brilliant, thanks, it prevents the scrollwheel from scrolling the image horizontally/vertically but I can continue to use my own methods.
I was originally using a MouseWheelListener (from swt.widgets) but swapping to a generic listener was a simple change.

Cheers!
Previous Topic:Access to desktop
Next Topic:How do I do a setText to a SWT text box ....
Goto Forum:
  


Current Time: Tue Jul 08 15:17:21 EDT 2025

Powered by FUDForum. Page generated in 0.45898 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top