[英]JFace TableViewer: Make cell background-color blink
我目前正在开发一个Eclipse RCP应用程序,它显示包含可编辑单元格的多个TableViewer
。 这些单元通过EMF数据绑定连接到我的模型。
现在我希望编辑后的单元格呈绿色闪烁,这意味着将背景颜色设置为绿色然后淡出。 为了方便入门,我想将单元格背景颜色设置为绿色,然后在1秒后恢复为白色。
原因是将背景颜色设置为绿色,但我不能让它在一秒钟后重新设置为白色,因为我正在编辑的ViewerCell
在ViewerCell
自动设置为null,我不知道为什么。
这是我的CellLabelProvider
的代码提取(不起作用):
@Override
public void update(final ViewerCell cell) {
//this works:
cell.setBackground(new Color(Display.getCurrent(), 0, 255, 0));
Display.getCurrent().timerExec(1000, new Runnable() {
public void run() {
//for this I get a NullPointerException:
cell.setBackground(new Color(Display.getCurrent(), 255, 255, 255));
}
});
}
任何帮助将非常感激!
修复程序中有一个与ViewerRow
中的ViewerCell
设置为null的ViewerCell
https://bugs.eclipse.org/bugs/show_bug.cgi?id=201280
要解决您遇到的问题,不应使用ViewerCell
。
试试这个代码
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public void update(final ViewerCell cell) {
cell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GREEN));
final int index = cell.getColumnIndex();
final TableItem item = (TableItem) cell.getItem();
Display.getCurrent().timerExec(1000, new Runnable() {
public void run() {
//make sure table is not disposed
item.setBackground(index, Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
}
});
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.