javaswingjpaneljtreetreecellrenderer

How do I make my TreeCellRenderer fill my JTree?


How do I make my tree cells fill the width of my JTree:

JTree tree = new JTree();
tree.setCellRenderer(new TreeCellRenderer() { 
    @Override
    public Component getTreeCellRendererComponent(JTree tree, Object value,
        boolean selected, boolean expanded, boolean leaf, int row, 
        boolean hasFocus) {
            // TODO: How do I make this panel fill the width 
            // of the JTree?
            JPanel panel = new JPanel();
            panel.add(new JLabel("ITEM");
            return panel;
        }
});
add(tree);

Solution