I have two ScrolledComposite
s and I'm synchronizing their vertical scroll positions like this:
final ScrollBar vScroll1 = canvasScroll.getVerticalBar();
final ScrollBar vScroll2 = titleScroll.getVerticalBar();
vScroll1.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
titleScroll.setOrigin(titleScroll.getOrigin().x, canvasScroll.getOrigin().y);
}
});
vScroll2.addSelectionListener(new SelectionAdapter() {
public void widgetSelected(SelectionEvent e) {
canvasScroll.setOrigin(canvasScroll.getOrigin().x, titleScroll.getOrigin().y);
}
});
This works fine, except it shows the scrollbars for both ScrolledComposites
. I only want one ScrolledComposite
's scrollbars to be visible, so I set one of their visibilities to false:
vScroll2.setVisible(false);
This has no effect. I also tried to instantiate the ScrolledComposite
without the SWT.V_SCROLL
flag, but this results in a null pointer exception when running the above code. The scrollbar does need to be there, I just want it to be invisible. Is that possible?
The simple answer is: "No".
If you create the
ScrolledComposite
withoutSWT.H_SCROLL
orSWT.V_SCROLL
, it cannot be scrolled, i.e. callingsetOrigin(Point)
or related methods simply won't do anything.If on the other hand, you enable scrollbars, but want to hide them, the OS will just override your decision. The scroll bars are controlled by the OS, meaning that the OS will decide if they are visible or not. Calling
setVisible(false)
on aScrollBar
is nothing more than a hint to the OS. It might follow it or not...Sorry to be the bearer of bad news :\
You could try wrapping the
ScrolledComposite
in anotherComposite
and forcing this one to "crop" the scrollbar of the containedScrolledComposite
(by changing its size), but this is more of a hack.