29 August 2004 - java_dev (original) (raw)

05:12 pm - sparkymark - JTree cells I have seen this problem mentioned in the Usenet archive periodically from 1998-2004 but have not seen an easy solution i.e. a solution other than implementing a TreeCellRenderer.When the text of a cell of a JTree becomes longer, as a result of that tree's event handler calling treeStructureChanged, then only text up to the previous length of the cell's text is displayed.( More...Collapse ) Edit: Extending DefaultTreeCellRenderer so that getTreeCellRendererComponent calls its "super" and then setPreferredSize on the object it returns (cast as JLabel), does most of the job, but the Dimension I used for setPreferredSize is arbitrarily large and so causes an unsightly blob of space at the end of the cell when it is highlighted. Is there a way to set the Dimensions of a JLabel so that it only just fits its text: presumably exactly this is happening somewhere in the bowels of DefaultTreeCellRenderer when the cell is initially rendered?