您的位置:首页 > 其它

有这样一个需求,左右各一个表格,要求拖动其中任意一个表格中的滚动条,另外一个都随之滚动,看起来就像是在一个表格中。

2011-08-03 20:58 323 查看
/** *//**
* 设置左边(右边)表格的滚动条根据右边(左边)滚动条滚动而滚动
*/
// Make selection the same in both tables

tParameterAlarm1.addListener(SWT.Selection, new Listener() ...{
public void handleEvent(Event event) ...{
tParameterAlarm2.setSelection(tParameterAlarm1.getSelectionIndices());
}
});
// On Windows, the selection is gray if the table does not have focus.

// To make both tables appear in focus, draw teh selection background

// here.
// This part only works on version 3.2 or later.

Listener eraseListener = new Listener() ...{
public void handleEvent(Event event) ...{
if ((event.detail & SWT.SELECTED) != 0) ...{
GC gc = event.gc;
Rectangle rect = event.getBounds();
gc.setForeground(container.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION_TEXT));
gc.setBackground(container.getDisplay().getSystemColor(
SWT.COLOR_LIST_SELECTION));
gc.fillRectangle(rect);
event.detail &= ~SWT.SELECTED;
}
}
};

tParameterAlarm1.addListener(SWT.EraseItem, eraseListener);
// Make vertical scrollbars scroll together

ScrollBar vBarLeft = tParameterAlarm1.getVerticalBar();
vBarLeft.addListener(SWT.Selection, new Listener() ...{
public void handleEvent(Event event) ...{
tParameterAlarm2.setTopIndex(tParameterAlarm1.getTopIndex());
}
});
tParameterAlarm2.addListener(SWT.Selection, new Listener() ...{
public void handleEvent(Event event) ...{
tParameterAlarm1.setSelection(tParameterAlarm2.getSelectionIndices());
}
});
tParameterAlarm2.addListener(SWT.EraseItem, eraseListener);
ScrollBar vBarRight = tParameterAlarm2.getVerticalBar();
vBarRight.addListener(SWT.Selection, new Listener() ...{
public void handleEvent(Event event) ...{
tParameterAlarm1.setTopIndex(tParameterAlarm2.getTopIndex());
}
});

其中tParameterAlarm1为左边表格的TableViewer,tParameterAlarm2为右边表格的TableViewer
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐