Changing color of a chechboxTableViewer input JFace

73 views Asked by At

I am having a CheckboxTableViewer with several entries. Now I need to display a few of the entries in a different color. Kindly help me to do this as I am very new to this topic. Thanks in advance.

checkboxTableViewer = CheckboxTableViewer.newCheckList(composite,
            SWT.BORDER | SWT.FULL_SELECTION);
checkboxTableViewer.setColumnProperties(new String[] {});
checkboxTableViewer.setAllChecked(false);
checkboxTableViewer.setAllGrayed(false);
table = checkboxTableViewer.getTable();
table.setFont(SWTResourceManager.getFont("Tahoma", 8, SWT.NORMAL));
table.setBounds(0, 10, 805, 277);
checkboxTableViewer.getTable().setLayoutData(
            new GridData(SWT.FILL, SWT.FILL, true, true));
checkboxTableViewer.setContentProvider(new ArrayContentProvider());
checkboxTableViewer.setInput(listSelCommit);
1

There are 1 answers

2
greg-449 On

Make your Label Provider implement IColorProvider, this adds two methods to the provider:

public MyLabelProvider extends LabelProvider implements IColorProvider
{
  ... other label provider methods

  @Override
  public Color getForeground(Object element)
  {
    // TODO return foreground color for 'element' or null to use the default
  }

  @Override
  public Color getBackground(Object element)
  {
    // TODO return background color for 'element' or null to use the default
  }
}