2011-12-01 85 views
1

我的對話框有兩個TreeViewer組件。垂直滾動條必須同步。 我試過setSelectionsetTopItem方法,但兩者對其他樹都沒有影響。滾動TreeViewer樹SWT

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

任何想法?

+0

什麼是'xViewerLeft'和'xViewerRight'? – CodyBugstein

回答

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

什麼是NSPoint? – CodyBugstein

+1

@Imray它是MAC操作系統特定的類,我asume可以使用Point而不是 –

+0

THanks。我的印象是SWT在所有系統中都可以工作。你能告訴我什麼是'xViewerLeft'和'xViewerRight'? – CodyBugstein