Changing Font of DefaultMutableTreeNode

From: Daniel Fabian (strap_at_fabiand.net)
Date: 03/27/04


Date: Sat, 27 Mar 2004 08:57:43 GMT

Hi!

I have a treenode and want to change the color and font of a treenode. I
have already implemented a TreeCellRenderer, but whenever I use that to
change the color of the font, the font of the whole tree changes. All I want
is to change a single TreeNode. What am I doing wrong?

private class LinkTreeCellRenderer extends DefaultTreeCellRenderer {
    public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
        super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf,
row, hasFocus);
        Object nodevalue = null;
        if (!(value instanceof DefaultMutableTreeNode))
            return this;
        nodevalue = ((DefaultMutableTreeNode)value).getUserObject();
        if ((nodevalue instanceof Page) && ((Page)nodevalue.someattr)) {
            setFont(this.getFont().deriveFont(Font.BOLD));
            setTextNonSelectionColor(Color.BLUE);
        }
        return this;
    }
}

Thanks in advance,
Daniel



Relevant Pages

  • Re: Changing Font of DefaultMutableTreeNode
    ... > I have a treenode and want to change the color and font of a treenode. ... > boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { ...
    (comp.lang.java.gui)
  • Re: using print in VBASIC 6
    ... You probably need to set the font. ... Optional Bold As Boolean, Optional Italic As Boolean, _ ... Optional Strikethrough As Boolean, Optional Underline As Boolean) As StdFont ...
    (microsoft.public.vb.bugs)
  • Re: How to resize a TreeNode after changing its font?
    ... Set the font of the TreeView to the bigger font at design ... >> the TreeNode's Text does no longer fit and it in the Bounds rectangle and ... >> Note that I do not want to change the Font property for the all TreeView, ... >> but only for that specific TreeNode. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: How to resize a TreeNode after changing its font?
    ... Set the font of the TreeView to the bigger font at design ... > the TreeNode's Text does no longer fit and it in the Bounds rectangle and ... > Note that I do not want to change the Font property for the all TreeView, ... > but only for that specific TreeNode. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Is there a better way to code this than constants?
    ... > array as you have coded) you can use enumerated values like this. ... > Personally if I had to do this I would have a class which had a TreeNode ... nsExpanded: boolean; ... nsFontColor: TColor; ...
    (alt.comp.lang.borland-delphi)