Using standalone SWT Scrollbars is something of a hack (using this workaround), but it can be done. Here s a snippet:
ScrolledComposite scrolledComposite = new ScrolledComposite(
parent, SWT.V_SCROLL);
ScrollBar scrollbar = scrolledComposite.getVerticalBar();
Shell tip = new Shell(UserInterface.getShell(), SWT.ON_TOP
| SWT.NO_FOCUS | SWT.TOOL);
// ..stylize and fill the tooltip..
Now what I m trying to do is monitor when the user is interacting with the scrollbar. In particular, I want to know when the user is dragging the scrollbar—and when it has been released—in order to display an Office 2007-style tooltip revealing which page the position of the scrollbar corresponds with.
Presently, I have the following code which displays the tooltip:
scrollbar.addSelectionListener(new SelectionListener() {
public void widgetDefaultSelected(SelectionEvent event) {}
public void widgetSelected(SelectionEvent event) {
tip.setVisible(true);
}
}
It would seem logical then to have the tooltip disappear when the mouse button is released:
scrollbar.addListener(SWT.MouseUp, new Listener() {
public void handleEvent(Event event) {
tip.setVisible(false);
}
});
However, neither scrollbar
nor scrolledComposite
seem to respond to the SWT.MouseUp
event when the user interacts with the scrollbar.
I presently have a workaround that hides the tip after a timeout, but I m not satisfied with this. Any insights would be most appreciated!