Originally posted by A Michaels:
Never mind - I figured it out. Needed to use a DefaultTreeModel and tell the model that the node had changed, so it woudl be redrawn correctly.
If you are firing the TreeModelEvents correctly, then
you should no longer need the explicit call to repaint(). The tree will repaint itself in response to the events.
btw, sometimes this exact symptom can be caused (even if the TreeModelEvents are being fired correctly) by a TreeCellRenderer that doesn't report its preferred width correctly. Your renderer doesn't have this problem, but I notice that your renderer is somewhat inefficient.
It probably doesn't matter unless your tree has a lot of nodes, but ideally your shouldn't be instantiating a Box and a JButton on every call to getTreeCellRendererComponent(). Instead do it once in your renderer's constructor and simply call setText() in getTreeCellRendererComponent().
Actually, you don't even need the Box. Just return the JButton unless you're going to put something else in it or give it a border or something.
Also, the way you have written it there's no point in calling super.getTreeCellRendererComponent(). (And once you omit that call there's no reason to extend DefaultTreeCellRenderer--just declare it to implement the TreeCellRenderer interface.)