Scrolling TreeViewer Tree SWT

2019-07-27 04:10发布

问题:

My dialog have two TreeViewer components. The vertical scroll bars have to be synchronized. I have tried with setSelection and setTopItem methods but both have no effect to other tree.

xViewerLeft = createXViewer(leftComposite, this);
xViewerRight = createXViewer(rightComposite, this);

xViewerLeft.getTree().getVerticalBar().addListener(SWT.Selection, new Listener() {
    @Override public void handleEvent(Event arg0) {
    //xViewerRight.getTree().setSelection(xViewerLeft.getTree().getSelection());
    //xViewerRight.getTree().setTopItem(xViewerLeft.getTree().getTopItem());
    }
});

Any ideas?

回答1:

The solution:

vBar1.addListener(SWT.Selection, new Listener() {
        @Override public void handleEvent(Event arg0) {
        double y = vBar1.getSelection()*xViewerRight.getTree().view.bounds().height/100;
        NSPoint nsPoint = new NSPoint();
        nsPoint.x = 0;
        nsPoint.y = y;
        xViewerRight.getTree().view.scrollPoint(nsPoint);
        }
    });