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);
JPanel panel = new JPanel();,JPanelis container,empty
JPanelby default returnszero Dimension,only empty
JPanel(AFAIK only) returns10pxinBorderLayotu, in the case that JPanels are placed to the NORTH, SOUTH, WEST, SOUTH areas, then created very nice 10pxsEmptyBordershave to override
getPreferredSizeforJPanel, the same ways as is required for Painting in Swingno idea for why reason you put
JPanelasRenderers JComponentintoJTree, maybe there is/are another way(s), sure for better help sooner post anSSCCE