Removing listeners from Scrollbar [solved] [message #686075] |
Tue, 21 June 2011 15:33 |
George Lawie 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 |
|
Lakshmi P Shanmugam Messages: 279 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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03062 seconds