java - JTree: TreeCellRenderer not doing as expected -
in nutshell, want tree rendered such first level bold.
public class treerenderer1 extends defaulttreecellrenderer { @override public component gettreecellrenderercomponent(jtree tree, object value, boolean sel, boolean exp, boolean leaf, int row, boolean hasfocus) { super.gettreecellrenderercomponent(tree, value, sel, exp, leaf, row, hasfocus); defaultmutabletreenode node = (defaultmutabletreenode)value; if (node.getlevel()==1) { setfont(getfont().derivefont(font.bold)); } return this; } }
this, however, make nodes in tree bold. wrong?
reset font state of render if level not 1
...
if (node.getlevel()==1) { setfont(getfont().derivefont(font.bold)); } else { setfont(getfont().derivefont(font.plain)); }
render's shared resource, changes make carried onto next element rendered, must make sure set "default" state @ point
Comments
Post a Comment