EclipseRCP开发之如何让左右两边两个表格协同滚动
2007-10-25 15:45
337 查看
有这样一个需求,左右各一个表格,要求拖动其中任意一个表格中的滚动条,另外一个都随之滚动,看起来就像是在一个表格中。具体如下图:
具体实现如下:
/** *//**
* 设置左边(右边)表格的滚动条根据右边(左边)滚动条滚动而滚动
*/
// 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
具体实现如下:
/** *//**
* 设置左边(右边)表格的滚动条根据右边(左边)滚动条滚动而滚动
*/
// 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
相关文章推荐
- EclipseRCP开发之如何让表格中的各列随表格的变化始终充满整个表格
- EclipseRCP开发之如何让表格中的各列随表格的变化始终充满整个表格
- EclipseRCP开发之如何让表格中的各列随表格的变化始终充满整个表格
- EclipseRCP开发之如何在表格前面加上多选框
- EclipseRCP开发之如何让表格中的各列随表格的变化始终充满整个表格
- 如何实现表格左右两边的边框为0
- 把页面分成左右两个,如何实现在左侧点击,链接一个页面到右边的页面
- 如何同步滚动两个相同的DataGrid
- Web表格开发如何避免Accessibility缺陷
- 如何同步滚动两个相同的DataGrid
- 华为如何实现基于Git的跨地域协同开发
- 如何在键盘出现时滚动表格,以适应输入框的显示
- div如何实现左右两个panel并排,而且高度一致
- div如何实现左右两个panel并排,而且高度一致
- Word表格如何设置上下居中对齐、左右居中对齐
- 输入一个32位的整数a,使用按位异或^运算,生成一个新的32位整数b,使得该整数b的每一位等于原整数a中该位左右两边两个bit位的异或结果
- 把页面分成左右两个,如何实现在左侧点击,链接一个页面到右边的页面
- 5.题目:输入一个32位的整数a,使用按位异或^运算,生成一个新的32位整数b,使得该整数b的每一位等于原整数a中该位左右两边两个bit位的异或结果 提示:0 ^ 0 = 0; 1 ^ 1 = 0;
- 【安卓-自定义布局】安卓App开发思路 一步一个脚印(十一)实现自定义左右滚动的导航栏目--仿美团
- 如何回答两个常见的开发求职面试问题