开发者

JTree with left and right-aligned text in cells?

开发者 https://www.devze.com 2022-12-17 11:22 出处:网络
What I\'m trying to do is create a JTree with each cell containing normal text but also containing a right-aligned text for each cell (right-aligned to the edge of the tree, regardless of the hierarch

What I'm trying to do is create a JTree with each cell containing normal text but also containing a right-aligned text for each cell (right-aligned to the edge of the tree, regardless of the hierarchy level).

I've tried creating my own TreeCellRenderer, but the开发者_如何学运维 cells' sizes are not being updated. I also tried this idea with a custom tree UI but am experiencing similar issues.

I also have tried creating a custom component with a JPanel "glued" to the right of the tree. This has been the most successful, but I have been unable to have the tree cells extend to the right and touch this extra panel:

alt text http://img718.imageshack.us/img718/3676/problem.png


You could try to use a JXTreeTable, from the SwingX package.

jxtreetable example http://blogs.sun.com/geertjan/resource/outline-tim-browser.png

You would define then such an object with two columns (one for the tree, to other for the right aligned text), and it should work out fine.

To prevent it from looking like a table, though, I would recommend you to deactivate the header (setTableHeader(null)), and use their "packing" methods, to have the columns on optimal size.

0

精彩评论

暂无评论...
验证码 换一张
取 消