Stop Auto-Scrolling in SWT When The User Grabs The Scrollbar

Imagine you have a console widget in an SWT app. The app is doing some background work and dumps lots of text in the console. Something catches the eye of the user and she desperately tries to keep it in view while the console jumps to the bottom all of the time. Here is a simple solution how to notice that the user has grabbed the scrollbar.

    private AtomicBoolean userHoldsScrollbar
                = new AtomicBoolean ();

        control.getVerticalBar ().addSelectionListener (new SelectionListener () {
            public void widgetDefaultSelected (SelectionEvent e)
                // NOP

            public void widgetSelected (SelectionEvent e)
                if (e.detail == SWT.DRAG)
                    userHoldsScrollbar.set (true);
                else if (e.detail == SWT.NONE)
                    userHoldsScrollbar.set (false);

In your auto-scroll code, check whether userHoldsScrollbar.get() is true.

One Response to Stop Auto-Scrolling in SWT When The User Grabs The Scrollbar

  1. Tamar Cohen says:

    That would be great if it worked, but in Eclipse 3.7.1 there is no callback to widgetSelected with e.detail == SWT.NONE; the listener only knows when it is being dragged and not when it was let go.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: