Skip to main content

JXTreeTable with Renderer to display no icons text problem

Please note these java.net forums are being decommissioned and use the new and improved forums at https://community.oracle.com/community/java.
1 reply [Last post]
luppy
Offline
Joined: 2008-05-01

Hi
I'm having a problem removing the icons from JXTreeTable whilst still preserving the text shown in the tree. When using a new DefaultTreeRenderer with IconValues.EMPTY the text disappears from the tree, should this happen. I've gone through a few examples and can't find a way to remove the icons and show the text.
An exmaple below, this does not show any text in the first column, comment out the line that sets the renderer shows the icon and text

import org.jdesktop.swingx.JXFrame;
import org.jdesktop.swingx.JXTreeTable;
import org.jdesktop.swingx.renderer.DefaultTreeRenderer;
import org.jdesktop.swingx.renderer.IconValues;
import org.jdesktop.swingx.treetable.DefaultMutableTreeTableNode;
import org.jdesktop.swingx.treetable.DefaultTreeTableModel;
import org.jdesktop.swingx.treetable.TreeTableNode;

import javax.swing.*;
import java.awt.*;

public class TreeTableTest extends JXFrame
{

    public TreeTableTest()
    {
        DefaultMutableTreeTableNode node1 = new DefaultMutableTreeTableNode();
        DefaultMutableTreeTableNode node2 = new DefaultMutableTreeTableNode();
        node1.add(node2);
        node2.add(new DefaultMutableTreeTableNode());

        ModelTest model = new ModelTest(node1);

        JXTreeTable table = new JXTreeTable(model);
        setLayout(new BorderLayout());
        add(new JScrollPane(table), BorderLayout.CENTER);

        // Comment out this line and tree text re-appears
        table.setTreeCellRenderer(new DefaultTreeRenderer(IconValues.NONE));

        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setSize(600, 400);
        setVisible(true);
    }

    private class ModelTest extends DefaultTreeTableModel
    {
        private ModelTest(TreeTableNode root)
        {
            super(root);
        }

        @Override
        public String getColumnName(int column)
        {
            return "Column " + column;
        }

        @Override
        public int getColumnCount()
        {
            return 3;
        }

        @Override
        public Object getValueAt(Object node, int column)
        {
            return "Some Text";
        }
    }

    public static void main(String[] args)
    {
        new TreeTableTest();
    }
}

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
luppy
Offline
Joined: 2008-05-01

Found out and solved it with

setTreeCellRenderer(new DefaultTreeRenderer(IconValues.NONE, StringValues.TO_STRING, false));