Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » TreeItem setBackGround() not working....(Default color of TreeItem not changing)
TreeItem setBackGround() not working.... [message #526679] Mon, 12 April 2010 15:10 Go to next message
Prasad  is currently offline Prasad Friend
Messages: 8
Registered: April 2010
Junior Member
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.... [message #526821 is a reply to message #526679] Tue, 13 April 2010 07:02 Go to previous messageGo to next message
Praveen  is currently offline Praveen Friend
Messages: 86
Registered: July 2009
Member
treeItem.setBackGround() sets the background of the item to specified
color, but it does *not* change the default selection color (of Windows
theme). In order to override the default selection color with your own
color, you might need to consider using custom drawing for the tree items.
For more info, refer to
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.sni ppets/src/org/eclipse/swt/snippets/Snippet229.java?view=co

HTH.,
Regards,
Praveen.
Re: TreeItem setBackGround() not working....Need help on changing TreeViewer selection default color [message #526884 is a reply to message #526821] Tue, 13 April 2010 11:56 Go to previous messageGo to next message
Prasad  is currently offline Prasad Friend
Messages: 8
Registered: April 2010
Junior Member
HI Praveen,

Thanks for your reply....

From your reply i came to know that.... i need to change the TreeViewer tree row background color....

My requirement is on selection of treeviewer item, i need to change the selection default color(blue) to some other color...

Can you please help if you have any idea of this kind..

Thanks,
Prasad.
Re: TreeItem setBackGround() not working....Need help on changing TreeViewer selection default color [message #526900 is a reply to message #526884] Tue, 13 April 2010 12:40 Go to previous messageGo to next message
Praveen  is currently offline Praveen Friend
Messages: 86
Registered: July 2009
Member
Refer to the link I've posted in my earlier reply.
Re: TreeItem setBackGround() not working....Need help on changing TreeViewer selection default color [message #526930 is a reply to message #526884] Tue, 13 April 2010 13:57 Go to previous messageGo to next message
Grant Gayed is currently offline Grant GayedFriend
Messages: 2150
Registered: July 2009
Senior Member
TreeViewer exposes the SWT Tree custom draw functionality through its
OwnerDrawLabelProvider. For an example of using OwnerDrawLabelProvider see
http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.jface.s nippets/Eclipse%20JFace%20Snippets/org/eclipse/jface/snippet s/viewers/Snippet010OwnerDraw.java?view=markup .

In your specific case you will need to provide an implementation of
OwnerDrawLabelProvider.erase(), in which you can do something like what
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/org. eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet226 .java
does in its EraseItem Listener.

Grant


"Prasad" <prasad.ramas@gmail.com> wrote in message
news:hq1m4k$7k1$1@build.eclipse.org...
> HI Praveen,
>
> Thanks for your reply....
>
> From your reply i came to know that.... i need to change the TreeViewer
tree row background color....
>
> My requirement is on selection of treeviewer item, i need to change the
selection default color(blue) to some other color...
>
> Can you please help if you have any idea of this kind..
>
> 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 06:34 Go to previous message
Prasad  is currently offline Prasad Friend
Messages: 8
Registered: April 2010
Junior Member
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.
Previous Topic:SWT ImageData -- How to obtain number of channels?
Next Topic:TreeViewer refresh() collapse problem-- SWT
Goto Forum:
  


Current Time: Sat Apr 20 02:21:44 GMT 2024

Powered by FUDForum. Page generated in 0.03367 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top