TableViewer & table cell color [message #275212] |
Thu, 04 November 2004 21:02 |
Eclipse User |
|
|
|
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 |
Eclipse User |
|
|
|
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
|
|
|
|
Powered by
FUDForum. Page generated in 0.03038 seconds