ITableColorProvider - color every other line (like greenbar paper) [message #444000] |
Tue, 07 February 2006 21:44 |
Eclipse User |
|
|
|
Originally posted by: kwpeck.mersoft.com
Looking at ITableColorProvider you get a call back for the element (the
row) and the column index but this gives you no hint as to what physical
row you happen to be painting. That means if you want to have a
different background color for each row it would be up to you to add a
row number to each element and keep all of that in sync during filtering
and sorting which I don't see as being possible.
Has anyone come up with a semi-generic solution to this issue?
We would not mind turning on grid lines if we could just turn on the
horizontal lines but you are not given that choice either. Grid lines
are all other nothing. I think it should be an option to enable
vertical, horizontal or both.
|
|
|
Re: ITableColorProvider - color every other line (like greenbar paper) [message #444003 is a reply to message #444000] |
Tue, 07 February 2006 22:48 |
Nick Messages: 34 Registered: July 2009 |
Member |
|
|
hi kevin,
i had exactly the same issues. only drawing the horizontal or
the vertical gridlines of the table would be great. however, i
don't know if this is possible at all, since the operating systems
would have to support this feature.
i'm sure there are better ways for solving the row coloring issue,
but i currently do it like this:
private int rowNum = 0
private Color COLOR_ODD = new Color(null, 237, 243, 254);
private Color COLOR_EVEN = new Color(null, 255, 255, 255);
public Color getBackground(Object element, int columnIndex) {
if (columnIndex == 0) rowNum++;
return (rowNum%2 == 0) ? COLOR_EVEN : COLOR_ODD;
}
hope it helps,
nick
Kevin Peck schrieb:
> Looking at ITableColorProvider you get a call back for the element (the
> row) and the column index but this gives you no hint as to what physical
> row you happen to be painting. That means if you want to have a
> different background color for each row it would be up to you to add a
> row number to each element and keep all of that in sync during filtering
> and sorting which I don't see as being possible.
>
> Has anyone come up with a semi-generic solution to this issue?
>
> We would not mind turning on grid lines if we could just turn on the
> horizontal lines but you are not given that choice either. Grid lines
> are all other nothing. I think it should be an option to enable
> vertical, horizontal or both.
|
|
|
Re: ITableColorProvider - color every other line (like greenbar paper) [message #444034 is a reply to message #444003] |
Wed, 08 February 2006 21:00 |
Eclipse User |
|
|
|
Originally posted by: kwpeck.mersoft.com
That works which is great although the code is a bit scary in that you
can wrap the integer after so many updates to the table (a lot for sure)
and I wonder if the repaint logic works the same on all support OS.
Obviously there is no optimized painting, it repaints whole table each
time and asks every single row / column on each paint.
I have written grids in the past and this is not the way I would have
done it but sometimes you just accept working code and move on with life.
Nick wrote:
> hi kevin,
>
> i had exactly the same issues. only drawing the horizontal or
> the vertical gridlines of the table would be great. however, i
> don't know if this is possible at all, since the operating systems
> would have to support this feature.
>
> i'm sure there are better ways for solving the row coloring issue,
> but i currently do it like this:
>
>
> private int rowNum = 0
> private Color COLOR_ODD = new Color(null, 237, 243, 254);
> private Color COLOR_EVEN = new Color(null, 255, 255, 255);
>
>
> public Color getBackground(Object element, int columnIndex) {
> if (columnIndex == 0) rowNum++;
> return (rowNum%2 == 0) ? COLOR_EVEN : COLOR_ODD;
> }
>
>
> hope it helps,
> nick
>
>
>
>
>
> Kevin Peck schrieb:
>> Looking at ITableColorProvider you get a call back for the element
>> (the row) and the column index but this gives you no hint as to what
>> physical row you happen to be painting. That means if you want to have
>> a different background color for each row it would be up to you to add
>> a row number to each element and keep all of that in sync during
>> filtering and sorting which I don't see as being possible.
>>
>> Has anyone come up with a semi-generic solution to this issue?
>>
>> We would not mind turning on grid lines if we could just turn on the
>> horizontal lines but you are not given that choice either. Grid lines
>> are all other nothing. I think it should be an option to enable
>> vertical, horizontal or both.
|
|
|
Re: ITableColorProvider - color every other line (like greenbar paper) [message #444037 is a reply to message #444034] |
Wed, 08 February 2006 23:00 |
Nick Messages: 34 Registered: July 2009 |
Member |
|
|
the integer won't wrap it you do it like this.
public Color getBackground(Object element, int columnIndex) {
if (columnIndex == 0)
if (rowNum%2==0) rowNum++;
else rowNum--;
return (rowNum == 0) ? COLOR_EVEN : COLOR_ODD;
}
however, i actually don't know if it works on all OS. never tried.
perhaps you should take a look at KTable. since it isn't
tied to the OS table widget it has more features.
nick
Kevin Peck schrieb:
> That works which is great although the code is a bit scary in that you
> can wrap the integer after so many updates to the table (a lot for sure)
> and I wonder if the repaint logic works the same on all support OS.
>
> Obviously there is no optimized painting, it repaints whole table each
> time and asks every single row / column on each paint.
>
> I have written grids in the past and this is not the way I would have
> done it but sometimes you just accept working code and move on with life.
>
> Nick wrote:
>> hi kevin,
>>
>> i had exactly the same issues. only drawing the horizontal or
>> the vertical gridlines of the table would be great. however, i
>> don't know if this is possible at all, since the operating systems
>> would have to support this feature.
>>
>> i'm sure there are better ways for solving the row coloring issue,
>> but i currently do it like this:
>>
>>
>> private int rowNum = 0
>> private Color COLOR_ODD = new Color(null, 237, 243, 254);
>> private Color COLOR_EVEN = new Color(null, 255, 255, 255);
>>
>>
>> public Color getBackground(Object element, int columnIndex) {
>> if (columnIndex == 0) rowNum++;
>> return (rowNum%2 == 0) ? COLOR_EVEN : COLOR_ODD; }
>>
>>
>> hope it helps,
>> nick
>>
>>
>>
>>
>>
>> Kevin Peck schrieb:
>>> Looking at ITableColorProvider you get a call back for the element
>>> (the row) and the column index but this gives you no hint as to what
>>> physical row you happen to be painting. That means if you want to
>>> have a different background color for each row it would be up to you
>>> to add a row number to each element and keep all of that in sync
>>> during filtering and sorting which I don't see as being possible.
>>>
>>> Has anyone come up with a semi-generic solution to this issue?
>>>
>>> We would not mind turning on grid lines if we could just turn on the
>>> horizontal lines but you are not given that choice either. Grid lines
>>> are all other nothing. I think it should be an option to enable
>>> vertical, horizontal or both.
|
|
|
Powered by
FUDForum. Page generated in 0.03005 seconds