如何使我的jface tableviewer显示特定行的所选背景颜色? 我在每一行都有一个时间戳,并且喜欢给出一个时间戳是星期一的颜色,与其他颜色不同。
答案 0 :(得分:4)
使用ColumnLabelProvider,它更容易:
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public Color getBackground(final Object element) {
if (element instanceof YourClass) {
if (((YourClass) element).shouldBeRed()) {
return new Color(Display.getDefault(), 0xFF, 0xDD, 0xDD);
}
}
return super.getBackground(element);
}
});
当然,您不应该在每个getBackground上创建新颜色,而是为此目的使用资源管理器。
答案 1 :(得分:0)
以下内容:
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public void update(final ViewerCell cell) {
YourRowItemClass rowItem = (YourRowItemClass) cell.getElement();
if (rowItem.isMonday()) {
cell.setBackground(Display.getDefault().getSystemColor(SWT.COLOR_DARK_GREEN));
}
}
});