SWT 3.1.1 Tree TreeItem background color columns treetable [message #462107] |
Thu, 06 October 2005 09:55  |
Eclipse User |
|
|
|
I am building a tree table using the new Tree functionality. When setting
the background on a TreeItem using SWT 3.1.1, only the item background color
in the Tree is set. The rest of the columns are not. In SWT 3.1.0, the
entire row background color was set.
The reason I need this to work is I have a recursive routine that alternates
row color, much like the behaviour of tables in GTK when showGrid is true.
I am using Windows, which of course shows a grid instead of alternating
colors. I call the routine after the tree is populated and when items are
expanded or collapsed.
Any answers to this problem are appretiated.
If anyone is interested, here is a snippet from my custom viewer:
int ri;
public void stripeRows(final TreeItem[] items)
{
ri = 0;
Display.getDefault().asyncExec(new Runnable() {
public void run()
{
traverseAndColor(items);
}
});
}
private void traverseAndColor(TreeItem[] items)
{
for (int i = 0; i < items.length; i++) {
TreeItem item = items[i];
if (ri % 2 == 0) {
item.setBackground(evenColor);
setControlsBackground(item, evenColor);
}
else {
item.setBackground(oddColor);
setControlsBackground(item, oddColor);
}
ri++;
if (item.getExpanded())
traverseAndColor(item.getItems());
}
}
private void setControlsBackground(TreeItem item, Color color)
{
if (item.getData() != null && item.getData() instanceof Control[]) {
Control[] controls = (Control[]) item.getData();
for (Control control : controls)
if (control != null) {
control.setBackground(color);
}
}
}
|
|
|
|
Powered by
FUDForum. Page generated in 0.03189 seconds