- summary: Fix for DefaultTreeCellRenderer CSS problem --> EchopointNG: Fix for DefaultTreeCellRenderer CSS problem
Hi,
I understand that you should be able to apply CSS
styles to the properties of the DefaultTreeCellRenderer
class. This does not appear to work for the current
EchopointNG code in CVS. In order to fix this, two minor
code changes are required:
1. In the Tree.validate method, the statment:
if(!referenceMap.containsKey(child))
this.remove(child);
should be modified to read:
if(!referenceMap.containsKey(child) && child != renderer)
this.remove(child);
to avoid the tree cell renderer from being removed from
the component hierarchy.
2. The DefaultTreeCellRenderer constructor is re-written
as:
public ReportEditorTreeCellRenderer() {
super();
saveBackground = super.getBackground();
saveForeground = super.getForeground();
saveFont = super.getFont();
}
And the
DefaultTreeCellRenderer.getTreeCellRendererText
method is updated to use getRenderProperty to retrieve
the selected foreground, background and font properties.
So the code below:
if (sel) {
super.setForeground(getSelectedForeground());
super.setBackground(getSelectedBackground());
if (getSelectedFont() == null)
super.setFont(tree.getFont());
else
super.setFont(getSelectedFont());
is replaced with the following:
if (sel) {
super.setForeground((Color)getRenderProperty
("selectedForeground"));
super.setBackground((Color)getRenderProperty
("selectedBackground"));
Font selectedFont = (Font)getRenderProperty
("selectedFont");
if (selectedFont == null)
super.setFont(tree.getFont());
else
super.setFont(selectedFont);
With these changes in place, I am now able to add
something like this to my css file:
echopointng.tree.DefaultTreeCellRenderer
{
selectedBackground: white;
selectedForeground: red;
selectedFont: font(arial,bold,10);
}
which now works as expected.
Hope that helps!
Jon