rich client 2.0

ScrolledComposite and the Mouse Wheel


3. October 2006
Tom Seidel @ 03:21

When using a ScrolledComposite, I always had the problem, that I couldn't use the wheel of my mouse for vertical scrolling. I was really annoyed about it. But now I have found a really simple solution.

Source Code

JAVA:
  1. final ScrolledComposite sc = new ScrolledComposite(parent, SWT.V_SCROLL);
  2. sc.addListener(SWT.Activate, new Listener() {
  3.     public void handleEvent(Event e) {
  4.         sc.setFocus();
  5.     }
  6. });

5 Comments »

  1. I had the same problem and the same solution. However, scrolling is *very* slow in my composite if it is used this way, compared to “native” JFace viewers like the TreeViewer. Do you happen to know of a remedy?

    -phil

    Comment by Phil — 12. April 2007 @ 09:26

  2. This snippet should enable scroll 3 times faster:
    sc.getVerticalBar().setIncrement(sc.getVerticalBar().getIncrement()*3);

    Tomas

    Comment by Tomas Krecmer — 24. April 2007 @ 10:37

  3. Thanks, this tip helped me out.

    Comment by Rob — 15. May 2008 @ 20:01

  4. @Tomas Thank you very much for the tip!

    Comment by thSoft — 30. September 2009 @ 14:56

  5. You’re the man, man!

    Comment by Pierre — 2. June 2010 @ 15:44

RSS feed for comments on this post. TrackBack URI

Leave a comment

Powered by WordPress