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();
,JPanel
is container,empty
JPanel
by default returnszero Dimension
,only empty
JPanel
(AFAIK only) returns10px
inBorderLayotu
, in the case that JPanels are placed to the NORTH, SOUTH, WEST, SOUTH areas, then created very nice 10pxsEmptyBorders
have to override
getPreferredSize
forJPanel
, the same ways as is required for Painting in Swingno idea for why reason you put
JPanel
asRenderers JComponent
intoJTree
, maybe there is/are another way(s), sure for better help sooner post anSSCCE