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.
(Some Usenet posts report the excess being replaced with "..." but I have not seen that).
One Usenet post says "The default TreeCelllRenderer goes nuts because the getPreferredSize [method of JLabel] is called just once when the tre is collapsed or expanded".
I am relying on the toString method of my nodes to display the text: if I recode them so that they pad out to one hundred characters with "x" then I don't "lose" any real data when the real-data changes length. Hardly a workaround! Replacing "x" with " " does not work as the rendering code trims the white space: even if it didn't, the highlighting of that node in the tree would look wrong.
Anyone know how to ensure the whole of the node.toString() is displayed when the tree updates itself?
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?
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.
(Some Usenet posts report the excess being replaced with "..." but I have not seen that).
One Usenet post says "The default TreeCelllRenderer goes nuts because the getPreferredSize [method of JLabel] is called just once when the tre is collapsed or expanded".
I am relying on the toString method of my nodes to display the text: if I recode them so that they pad out to one hundred characters with "x" then I don't "lose" any real data when the real-data changes length. Hardly a workaround! Replacing "x" with " " does not work as the rendering code trims the white space: even if it didn't, the highlighting of that node in the tree would look wrong.
Anyone know how to ensure the whole of the node.toString() is displayed when the tree updates itself?
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?
