Java Swing table tree
Asked Answered
A

3

13

When you open a XML in Eclipse, the content can be shown in as a tree structure like

XML tree view

The tree is "embedded" in a table and the content is showed in a seperate column.

This would be very nice to replicate in Swing, not for XML content specifically, but for similar data with tree structure.

UPDATE

I just learned about JTreeTable, but I really need to do this in NetNeans. Should probably have mentioned that, sorry.

Any ideas?

Avigation answered 19/8, 2011 at 14:15 Comment(2)
What do you mean by "do it in Netbeans"? Do you need to use the component in a GUI designer?Nika
@Nika - Yes, It's for work.Avigation
E
15

SwingX has a JXTreeTable, it's based on but much improved over the oldish examples (links to sun code/article) cited by @mKorbel

Excavate answered 19/8, 2011 at 14:45 Comment(3)
@Excavate - For NetBeans, i'm not so sure, see #5613282Avigation
@Theodor: repeating myself (the comment I made there) - mixing a beaninfo 0.9.7 with a swingx of 1.6 is certain to pose problems ;-)Excavate
@Excavate - After some head scratching, JXTreeTable works beautiful. Sorry that I doubted you =) Thank you.Avigation
P
6

Check the following:

Program answered 19/8, 2011 at 14:40 Comment(0)
S
1

You could try subclassing JTable and making your own custom renderer with behavior that adds/removes new rows when you expand/collapse a node.

Scene answered 19/8, 2011 at 14:26 Comment(2)
-1 - you tried it? Very unlikely to get anything half-way robust by on-the-fly custom renderers, there's more issues to solve than mere visuals. Though, at it's very base, the typical J/X/TreeTable implementations do have a custom renderer for the hierarchical column :-)Excavate
+1 I do it this way already, vary fast for large data sets. The renderer has to render the indentation and the collapse/expand icon, too.Mac

© 2022 - 2024 — McMap. All rights reserved.