EclipseRCP开发之如何让左右两边两个表格协同滚动

出自:http://blog.csdn.net/kevin99zhang/archive/2007/10/25/1843463.aspx
有这样一个需求,左右各一个表格,要求拖动其中任意一个表格中的滚动条,另外一个都随之滚动,看起来就像是在一个表格中。
具体实现如下:
  /** *//**
* 设置左边(右边)表格的滚动条根据右边(左边)滚动条滚动而滚动
*/
// 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
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值