Thursday, October 06, 2005

JTree row truncation problem

Been having a problem (not a huge one) with a JTree on a JScrollPane in a JSplitPane using an extension of DefaultTreeCellRenderer.

When the cells of the tree containing strings, where made longer they tended to get truncated with "..." despite there being enough room in the JSplitPane to accommodate the change and that it would have been possible to add a scroll bar.

After a whole lot of stuffing around and trawling search engines I found the solution here. The second to last post contains the solution.

tree.setLargeModel(true);

tree.setRowHeight( [non-zero positive value] );


I turns out that JTree caches the cell dimensions, not surprising if you see the problem occurring. So by setting the above fields it seems to turn the caching off. Trade off being that the row height is fixed.

I haven't investigated if using a custom implementation of TreeCellRender that uses a JPanel rather than a JLabel to work better, but since I'm using icons it would mean replicating much of what JLabel does.

Comments:
Thanks a lot!
 
Post a Comment



<< Home

This page is powered by Blogger. Isn't yours?