EclipseRCP开发之如何让左右两边两个表格协同滚动
来源:互联网 发布:js文件获取el表达式值 编辑:程序博客网 时间:2024/05/15 23:46
有这样一个需求,左右各一个表格,要求拖动其中任意一个表格中的滚动条,另外一个都随之滚动,看起来就像是在一个表格中。具体如下图:
具体实现如下:
其中tParameterAlarm1为左边表格的TableViewer,tParameterAlarm2为右边表格的TableViewer
具体实现如下:
/**
* 设置左边(右边)表格的滚动条根据右边(左边)滚动条滚动而滚动
*/
// 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());
}
});
* 设置左边(右边)表格的滚动条根据右边(左边)滚动条滚动而滚动
*/
// 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());
}
});
- EclipseRCP开发之如何让左右两边两个表格协同滚动
- EclipseRCP开发之如何让表格中的各列随表格的变化始终充满整个表格
- EclipseRCP开发之如何让表格中的各列随表格的变化始终充满整个表格
- EclipseRCP开发之如何让表格中的各列随表格的变化始终充满整个表格
- EclipseRCP开发之如何让表格中的各列随表格的变化始终充满整个表格
- EclipseRCP开发之如何在表格前面加上多选框
- 如何实现表格左右两边的边框为0
- 支持左右两边同时滚动的Progressbar
- EclipseRCP开发之增加右键菜单
- EclipseRCP开发之动态的加入视图
- EclipseRCP开发之捕获视图关闭事件
- 如何让表格在超出高度出现滚动条
- 如何让两个或多个Excel表格独立显示
- 如何实现网页左右两边盒子高度自适应布局
- 我的开发之路之如何让ListView滚动到第一行
- EclipseRCP开发之屏蔽视图上的右键菜单
- EclipseRCP开发---【第一弹】
- 左右两边div布局
- 关于如何添加桌面快捷方式
- 学习Core Java第一天的课堂笔记!
- 开博了...哈哈!
- 如何利用Xerces C++正确处理XML文档中的WhiteSpace
- 长盛同德基金10月26-11月16日发行认购代码为519039,费率不超1.5%
- EclipseRCP开发之如何让左右两边两个表格协同滚动
- 如何利用Xerces C++解析包含中文字符的XML文档
- quest经验谈
- Hibernate检索对象的方式(查询一)
- Django下碰到EF BB BF问题
- ASP.NET 2.0中使用自定义provider (2)
- Windows快捷键大全
- Hibernate(分组查询等续)
- 转:使用eclipse(v3.01)与mingw(v3.1.0)搭建Windows下C/C++开发环境