1

I have a TreeEditor and some text in its first column. I need to append some text to it using a label or string. In addition, I want to change the color of the appended string to green. I tried to do it with this code, but it isn't working:

Label label = new Label(this.tree ,SWT.RIGHT);
label.setFont(new Font(getSite().getShell().getDisplay(), ("Hello"), 18,
        SWT.BOLD));
label.setText("hello:));
label.pack();
treeItem.setText(1, hi + "        " + label.getText());

How could I accomplish this?

APerson
  • 8,140
  • 8
  • 35
  • 49
rekha
  • 21
  • 2
  • Setting color in swt see this http://stackoverflow.com/questions/50064/setting-colors-in-swt – Maadh Mar 12 '13 at 13:41
  • By the way, there's an error in the code posted; there is no closing quote in the string for "hello:" at line 3. – APerson Mar 12 '13 at 13:42
  • 1
    Do you want to have the TreeItem's text in *two* different colors? I do not see any simple solution. One way would be to use two columns. Consider JFace and ColumnLabelProvider in this case. Otherwise try embedding your own custom control into the tree. – Claude Mar 12 '13 at 13:52

1 Answers1

2

you might want to look at org.eclipse.jface.viewers.DecoratingStyledCellLabelProvider

sambi reddy
  • 3,065
  • 1
  • 13
  • 10