TreeItem setBackGround() not working.... [message #526679] |
Mon, 12 April 2010 11:10  |
Eclipse User |
|
|
|
Hi,
SWT-- TreeViewr-- TreeItem
In the following code i am trying to change the background color of the TreeItem dynamically on selection of the TreeItem, but its not changing the default color.. still its showing the default blue color....
Please help me on this......
private TreeViewer tableTreeViewerSource;
//adding the listener to the treeviewer
tableTreeViewerSource.addSelectionChangedListener(new ISelectionChangedListener(){
public void selectionChanged(SelectionChangedEvent event) {
IStructuredSelection selection = (IStructuredSelection)event.getSelection();
Object obj = selection.getFirstElement();
TreeItem sourceItem = ComparatorUIUtils.getMatchedTreeItem(((Componenet)obj).getRe fNumber(), tableTreeViewerSource.getTree().getItems(),null);
//i got the treeitem
//trying to change the color
sourceItem.setBackground(sourceItem.getDisplay().getSystemCo lor(SWT.COLOR_DARK_GREEN));
}
});
I want to change the color of the treeitem..as Green
Please help me on this..
Thanks,
Prasad.
|
|
|
|
|
|
|
Re: TreeItem setBackGround() not working....Need help on changing TreeViewer selection default color [message #528051 is a reply to message #526930] |
Mon, 19 April 2010 02:34  |
Eclipse User |
|
|
|
Thanks alot guys...its working...
I followed suggestion by looking at the code snippets that you guys suggested...
I tried adding listner to the tree as following and it works:
treeViewer.getTree().addListener(SWT.EraseItem, new Listener(){
public void handleEvent(Event event) {
if ((event.detail & SWT.SELECTED) == 0) return; /* item not selected */
int clientWidth = treeViewer.getTree().getClientArea().width;
GC gc = event.gc;
gc.setForeground(treeViewer.getTree().getDisplay().getSystem Color(SWT.COLOR_TITLE_FOREGROUND));
gc.setBackground(treeViewer.getTree().getDisplay().getSystem Color(SWT.COLOR_BLUE));
gc.fillRectangle(0, event.y, clientWidth, event.height);
event.detail &= ~SWT.SELECTED;
}});
Thanks,
Prasad.
|
|
|
Powered by
FUDForum. Page generated in 0.04357 seconds