Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 15:33 Go to next message
George Lawie is currently offline George LawieFriend
Messages: 10
Registered: December 2010
Junior Member
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 14:40]

Report message to a moderator

Re: Removing listeners from Scrollbar [message #686521 is a reply to message #686075] Wed, 22 June 2011 12:20 Go to previous messageGo to next message
Lakshmi ShanmugamFriend
Messages: 276
Registered: July 2009
Location: India
Senior Member
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
}
});


Lakshmi P Shanmugam

[Updated on: Wed, 22 June 2011 12:21]

Report message to a moderator

Re: Removing listeners from Scrollbar [message #686560 is a reply to message #686521] Wed, 22 June 2011 13:48 Go to previous message
George Lawie is currently offline George LawieFriend
Messages: 10
Registered: December 2010
Junior Member
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 Feb 18 09:42:40 GMT 2020

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

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

Back to the top