Search code examples
javaimageswingjtreerenderer

Two images in JTreeNode?


I have some custom JTree. That tree has nodes with custom icons. I also have a class that extends DefaultTreeCellRenderer with method getTreeCellRendererComponent as simple as this:

super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
MyTreeNode node = ((MyTreeNode) value);
Icon icon = node.getIcon();
setIcon(icon);
return this;

It works. My tree nodes will be rendered with custom icons in ICON TEXT format. BUT! Is there a way to put TWO icons in my node! I would like to have a node that looks like this: ICON TEXT ANOTHER_JLABEL_WITH_IMAGE.

How to do it?


Solution

  • You should create your own TreeCellRenderer that extends from something like a JPanel.

    This way, you can define your own layout requirements and add your own components to support your requirements