Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » TableViewer & table cell color
TableViewer & table cell color [message #275212] Thu, 04 November 2004 21:02 Go to next message
Eclipse UserFriend
Originally posted by: nospam_st.gmx.net

How can I modify the front or background color of a table cell
programatically. LabelProvider is obviously only responsible to provide
the text to be displayed in a table cell. In my case the underlying
table has a column displaying numeric values. I want to get them
displayed in black when they are positive and in red when they are
negative.

Thanks for any ideas in advance!

Seb
Re: TableViewer & table cell color [message #275245 is a reply to message #275212] Fri, 05 November 2004 14:29 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: rajbsaini.yahoo.com

Sebastian wrote:
> How can I modify the front or background color of a table cell
> programatically. LabelProvider is obviously only responsible to provide
> the text to be displayed in a table cell. In my case the underlying
> table has a column displaying numeric values. I want to get them
> displayed in black when they are positive and in red when they are
> negative.

It is possible to change the color of whole table row and not individual
cells (is it possible?, I will be glad to hear that). You can implement
the IColorProvider Interface to give color to your table rows.

public class YourViewLabelProvider extends LabelProvider implements
ITableLabelProvider, IColorProvider
{

public String getColumnText(Object element, int columnIndex)
{
//Your getColoumnText() implementation
}
/* (non-Javadoc)
* @see
org.eclipse.jface.viewers.IColorProvider#getForeground(java. lang.Object)
*/
public Color getForeground(Object element)
{
return null; //return forgroud color
}

/* (non-Javadoc)
* @see
org.eclipse.jface.viewers.IColorProvider#getBackground(java. lang.Object)
*/
public Color getBackground(Object element)
{
StockQuote quote = (StockQuote) element;
if ((quote.getVarPercentage() < 0)) {
// Red background if balance negative.
return Display.getCurrent().getSystemColor(SWT.COLOR_RED);
}
//Return back ground color
return Display.getCurrent().getSystemColor(SWT.COLOR_GREEN);

}
}


Raj

> Thanks for any ideas in advance!
>
> Seb
Re: TableViewer & table cell color [message #275252 is a reply to message #275212] Fri, 05 November 2004 15:23 Go to previous message
Tod Creasey is currently offline Tod CreaseyFriend
Messages: 59
Registered: July 2009
Member
In 3.1 M3 there is now an ITableColorProvider and an ITableFontProvider that
can be used to determine cell colors and fonts.

Tod Creasey
Platform UI Team

"Sebastian" <nospam_st@gmx.net> wrote in message
news:cme5dd$57r$1@eclipse.org...
> How can I modify the front or background color of a table cell
> programatically. LabelProvider is obviously only responsible to provide
> the text to be displayed in a table cell. In my case the underlying
> table has a column displaying numeric values. I want to get them
> displayed in black when they are positive and in red when they are
> negative.
>
> Thanks for any ideas in advance!
>
> Seb
Previous Topic:Replacing an action in popup menu
Next Topic:Listener for recently modified
Goto Forum:
  


Current Time: Mon Dec 30 17:11:18 GMT 2024

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

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

Back to the top