I have asked a very similar question, but I ended up using images instead of changing the color.
I want all the text in the cells to be dark grey. I understand that you have to assign each column. But I do not how to do it.
This is one of my columns in my TableViewer.
col = new TableViewerColumn(this , SWT.NONE);
col.getColumn().setWidth(200);
col.getColumn().setText("Printer/Profile");
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public String getText(Object element) {
AplotResultsDataModel.ResultsData p = (AplotResultsDataModel.ResultsData) element;
return p.getPrinterProfile();
}
});
How would I change the above code to incorporate setting the font color to dark gray?
EDIT
If I am using the switch, how does it know how many columns I have? also how do I set the column names? Here is how I have it set up right now
TableViewerColumn col = new TableViewerColumn(this , SWT.NONE);
col.getColumn().setWidth(150);
col.getColumn().setText("ItemId");
col.setLabelProvider(new ColumnLabelProvider() {
@Override
public void update(ViewerCell cell)
{
Object element = cell.getElement();
if(element instanceof AplotPDFDataModel.FileNameData)
{
AplotPDFDataModel.FileNameData p = (AplotPDFDataModel.FileNameData) element;
cell.setForeground(ColorConstants.darkGray);
switch(cell.getColumnIndex())
{
case 0:
try {
cell.setText(p.getRev().getStringProperty("item_id"));
}
catch (TCException e) {
e.printStackTrace();
}
break;
case 1:
try {
cell.setText(p.getRev().getStringProperty("item_revision_id"));
}
catch (TCException e) {
e.printStackTrace();
}
break;
case 2:
cell.setText(p.getPRLValue().toString());
break;
case 3:
cell.setText(p.getMarkupValue());
break;
case 4:
cell.setText(p.getFileName());
break;
}
}
}
});