更改SWT表的单元格字体颜色

Rab*_*bin 2 java swt eclipse-rcp

我在Eclipse RCP项目中使用以下行:

item.setForeground(3, dis.getSystemColor(SWT.COLOR_RED));
Run Code Online (Sandbox Code Playgroud)

我有什么理由不改变颜色吗?我只有一个特定的细胞有红色前景.

Din*_*del 6

如果你正在使用Eclise-rcp试试这个

Display display =PlatformUI.getWorkbench().getDisplay();
Color red = display.getSystemColor(SWT.COLOR_RED);
YourTable.getItem(i).setForeground(red);
Run Code Online (Sandbox Code Playgroud)

注意:i是要更改颜色的表项的索引.

如果你想改变代码所特定单元格的特定单元格的颜色

YourTable.getItem(i).setForeground(2, red); // 2 means that you column on index 2 will be colored
Run Code Online (Sandbox Code Playgroud)