滚动TreeViewer树SWT

时间:2011-12-01 20:21:17

标签: java tree swt treeviewer

我的对话框有两个TreeViewer个组件。垂直滚动条必须同步。 我尝试使用setSelectionsetTopItem方法,但两者都对其他树没有影响。

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());
    }
});

有什么想法吗?

1 个答案:

答案 0 :(得分:-2)

解决方案:

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);
        }
    });