Reputation: 171
I have done research into this for a while now and have found very little information on SWT MouseWheelListeners
. Looking to see if any of you have encountered this or have a link to something that could help explain them.
I am trying to find out information on the SWT MouseWheelListener
and how it is used appropriately. I am attempting to use the MouseWheelListener
to create a zoom effect on a composite which draws multiple composite objects on it.
In essence, when wheeling up zoom in by redrawing the canvas at twice normal size, repainting objects on the canvas in a proportional layout, and moving the focus to the point wheeled on.
My questions are the following:
Is it possible to use a MouseWheelListener
on a Composite or is the listener only for objects like scrolled composites (I know the method is there; nothing is happening when I attempt to scroll on my object (including at debug)?
How to kick off a MouseScrolledEvent
on a Composite
if possible?
How to differentiate between wheel up and wheel down (e.count is positive for up & negative for down)?
Code follows:
public TagCloudComposite(Composite parent, int style) {
super(parent, style);
addMouseWheelListener(new MouseWheelListener() {
public void mouseScrolled(MouseEvent e) {
int count = e.count;
System.out.println(count);
// int direction = (Math.abs(count) > 0) ? UP : DOWN;
// changeBackground(direction);
}
});
this.setLayout(new FillLayout());
this.setMinWeight(1);
this.setMaxWeight(100);
c = new Composite(this, SWT.NONE);
this.setSize(300, 200);
}
Upvotes: 1
Views: 5700
Reputation: 61
It is possible to use the MouseWheelListener on a canvas; the only thing is that the event trigger only on the component with the focus.
A canvas don't usually get focus, unless you add a key listener to it (even an empty one).
(I know the question is quite old, but faced with the same issue google directed me there so here's a solution).
Upvotes: 2
Reputation: 21
Yes, you're right. "Count" here means number of scroll lines (3 or -3 by default in Windows)
Upvotes: 2