Skip to main content

JXTreeTable and font highlighter (BoldHighlighter)

Please note these forums are being decommissioned and use the new and improved forums at
2 replies [Last post]
Joined: 2005-09-29

There is a bug in JXTreeTable since very early versions of SwingX which is still there:

I have made a BoldHighligher which displays the highlighted item in bold.
In JXTree, it works as expected.
In JXTreeTable, as soon as one element is highlighted, all subsequent elements are also highlighted. I believe that the font of the renderer is not reset at each cell...?

Here is the code:

public class BoldHighlighter extends AbstractHighlighter {
private Font BOLD_FONT = null;

public BoldHighlighter(final HighlightPredicate predicate) {

protected Component doHighlight(Component renderer, ComponentAdapter adapter) {
if (BOLD_FONT == null) {
BOLD_FONT = renderer.getFont().deriveFont(Font.BOLD);


return renderer;

Many thanks!
(Kleopatra, I had talked to you about a similar bug few years back :-)

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2005-09-29

And the small runnable code:

package testhighlighter;

import java.awt.BorderLayout;
import java.awt.Component;

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;

import org.jdesktop.swingx.JXTreeTable;
import org.jdesktop.swingx.decorator.ComponentAdapter;
import org.jdesktop.swingx.decorator.HighlightPredicate;
import org.jdesktop.swingx.renderer.DefaultTreeRenderer;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;

public class TreeTableTest {

public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JXTreeTable tree = new JXTreeTable();

tree.setTreeCellRenderer(new DefaultTreeRenderer());

DefaultMutableTreeTableNode rootNode = new DefaultMutableTreeTableNode("Hello");
for (int i = 0; i < 10; i++) {
rootNode.add(new DefaultMutableTreeTableNode("a node"));
rootNode.add(new DefaultMutableTreeTableNode("b node"));

tree.setTreeTableModel(new DefaultTreeTableModel(rootNode));

tree.addHighlighter(new BoldHighlighter(new HighlightPredicate() {
public boolean isHighlighted(Component renderer, ComponentAdapter adapter) {
return adapter.getValue().toString().startsWith("a");

JFrame frame = new JFrame("Test");
frame.setLayout(new BorderLayout());

frame.getContentPane().add(new JScrollPane(tree));

Joined: 2003-06-11

yeah, we are aware of the issue: the base reason is that the JXTree which is used as a renderer in the hierarchical column is not a ComponentProvider (and consequently indeed not updated as needed)

No pending plans to fix it, sorry - thanks for the example, though!