默认情况下,SWT的Table只会给整个Table设置Tooltip,要对每一个TableItem设置Tooltip的话,就要监听鼠标事件了:
table.addMouseTrackListener(new MouseTrackAdapter() {
public void mouseHover(MouseEvent event) {
Point pt = new Point(event.x, event.y);
int index = table.getTopIndex();
while (index < table.getItemCount()) {
TableItem item = table.getItem(index);
for (int i = 0; i < table.getColumnCount(); i++) {
Rectangle rect = item.getBounds(i);
if (rect.contains(pt)) {
Object object= item.getData();
........
}
}
index++;
}
}
});
在省略号的地方就可以对对象进行转型了