有这样一个需求,左右各一个表格,要求拖动其中任意一个表格中的滚动条,另外一个都随之滚动,看起来就像是在一个表格中。
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
* 设置左边(右边)表格的滚动条根据右边(左边)滚动条滚动而滚动
*/
// 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
相关文章推荐
- 实现这样一个表格,有横竖滚动条,竖滚动条不包括头部,横滚动条包括头部,竖滚动条滚动时头部不动,横滚动条滚动时头部动,表格单元格宽度不固定。
- 输入任意大小的三个整数,判断其中是否有两个奇数一个偶数。若是,则输出“YES”,不是则输出“NOT” (要求用条件表达式进行判断,不使用if语句)
- 任意输入20个正整数,找出其中的素数,并将这些素数按由小到大排序。要求:判断一个数是否为素数用函数实现:排序用函数实现
- 二、给定一个 n 行 m 列的地牢,其中 '.' 表示可以通行的位置,'X' 表示不可通行的障碍,牛牛从 (x0 , y0 ) 位置出发,遍历这个地牢,和一般的游戏所不同的是,他每一步只能按照一些指定的步长遍历地牢,要求每一步都不可以超过地牢的边界,也不能到达障碍上。地牢的出口可能在任意某个可以通行的位置上。牛牛想知道最坏情况下,他需要多少步才可以离开这个地牢。
- [转]界面上有两个DataGridView,其中的一个的水平滚动条滚动时,另外一个的水平滚动条也能够滚动相同的的距离
- 界面上有两个DataGridView,其中的一个的水平滚动条滚动时,另外一个的水平滚动条也能够滚动相同的的距离
- 输入一个高精度的正整数n,去掉其中任意s个数字后剩下的数字按原左右次序将组成一个新的正整数。编程对所给的n和s,寻找一种方案使得剩下的数字组成的新数最小。
- samba需求,请建一个目录,所有用户都可以修改其中的任意文件(新建文件的权限问题)
- 一串首尾相连的珠子(m个),有N种颜色(N《=10),设计一个算法,取出其中一段,要求包含所有N中颜色,并使长度最短。并分析时间复杂度与空间复杂度。
- 【安卓-自定义布局】安卓App开发思路 一步一个脚印(十一)实现自定义左右滚动的导航栏目--仿美团
- 输入两个数,并显示他们,但拒绝接受两个数都大于10的情况,且要求用户从新输入.看看其中的一个(但不是两个)是否大于10.
- 将多个Datatable合并到另外一个DataTable中,并获取其中有用的值
- jquery实现div内图片水平左右滚动,滚动到最后一张停止、可根据需求调整图片数量及大小
- 着手公司两个大项目的架构,其中一个要求ASP.NET 2.0,技术调查中.
- 一个int数组, 比如 array[],里面数据无任何限制,要求求出 所有这样的数array[i],其左边的数都小于等于它,右边的数都大于等于它。能否只用一个额外数组和少量其它空间实现
- 对于一个整数矩阵,存在一种运算,对矩阵中任意元素加一时,需要其相邻(上下左右)某一个元素也加一, 现给出一正数矩阵,判断其是否能够由一个全零矩阵经过上述运算得到。
- 陈利人 面试题 对于一个n位正整数a,去掉其中任意k(k<=n)个数字后,剩下的数字按原次序排列可以组成一个新的正整数。设计一个删数算法,使得剩下的数字组成的正整数最小。
- 有一堆扑克牌,其中某张牌的张数超过了扑克牌总数的一半,请找到这张牌。写出算法思路、代码实现和算法的时间复杂度,要求算法尽可能高效。假设给定一个扑克牌的数组poker和它的大小n,请返回所求的扑克牌。
- 字符串匹配之通配符问题------一串首尾相连的珠子(m个),有N种颜色(N《=10),设计一个算法,取出其中一段,要求包含所有N中颜色,并使长度最短。
- 如何判断任意四个点可以组成矩形及正方形 && 点绕另外一个点旋转后的坐标