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.
Tagged: Java, SWT