I'm putting two TreeViewers
in an SWT Shell
.
They each have their own scrollbars. However, I would like to have only one Scrollbar
in the Shell
which controls the scrolling of both TreeViewers
simultaneously.
The only example of this I've been able to find is in the Source Compare View. However, I cannot see how they did this - I have been trying to figure it out for a while. But at least I know it's possible.
Any suggestions?
EDIT
My final interface should have two TreeViewers
and one Scrollbar
at the left to control them both.
This should help you out. When i used SWT.NO_SCROLL
for the Tree
it stopping scrolling but Table
, it hides vertical scroll bar and Table was scrolled when top index is set.
Tree
use setTopItem(TreeItem)
-read documentation( as treeitem has child items )
Table
use setTopIndex(int index)
example:
Display display = new Display();
Shell shell = new Shell(display);
shell.setLayout(new GridLayout(2,false));
final Tree tree1 = new Tree(shell, SWT.BORDER | SWT.MULTI /*| SWT.NO_SCROLL*/);
for (int i = 0; i < 128; i++) {
TreeItem item = new TreeItem(tree1, SWT.NONE);
item.setText("Tree 1 Item" + i);
}
GridData data = new GridData(SWT.FILL, SWT.FILL, false, false);
data.heightHint=200;
tree1.setLayoutData(data);
final Tree tree2 = new Tree(shell, SWT.BORDER | SWT.MULTI);
tree2.setSize(200, 200);
for (int i = 0; i < 128; i++) {
TreeItem item = new TreeItem(tree2, SWT.NONE);
item.setText("Tree 2 Item" + i);
}
tree2.getVerticalBar().addSelectionListener(new SelectionListener() {
@Override
public void widgetSelected(SelectionEvent e) {
TreeItem item = tree2.getTopItem();
int i = tree2.indexOf(item);
item = tree1.getItem(i);
tree1.setTopItem(item);
}
@Override
public void widgetDefaultSelected(SelectionEvent e) {
}
});
data = new GridData(SWT.FILL, SWT.FILL, false, false);
data.heightHint=200;
tree2.setLayoutData(data);
shell.pack();
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With