Putting a JTable inside a JTree

Hello,

Does anyone have any experience with the subject line. I am creating an object viewer that uses reflection to display all the fields of a selected Object. Object type fields will be a tree node that can be expanded and will just have the name of the field as a JLabel. All the primitive data types will be a single tree node as a JTable that can be edited. I am currently having two problems:

1.) The table is being partially displayed, I can see all the data but the left and top border of the table is missing

2.) I can’t select anything, it seems to me that cells can
be highlighted by default on a JTable usually.

I could probably solve everything by making a custom table using JPanels,JLabels,JTextBox, and GridLayout but just wondering if I am missing anything obvious(which is usually the case!). This may not seem related to game development but I am creating an application so that I can view my simple scenegraph and change values on the fly to see the result.

Thanks,
Steve

Hello,

How come everytime I post a question somewhere I always find what I am looking for and I usually find my original question is a stupid one ::slight_smile: . I found the answer to number 2 (set editable on the tree and write a TreeCellEditor) however number 1 is still a problem.

Thanks,
Steve

have you tried putting all the JTables on JPanels? My first and only thought is to add the table to a panel ( BorderLayout.CENTER ), throw those in the tree, and see how it looks.

I would try this if I felt I had time to screw around with it … curious component composition.

If you get this working I’d love to see a screen shot and hear how ya did it. :slight_smile:

[quote]Hello,

Does anyone have any experience with the subject line.
[/quote]
IIRC do a google for “JTableTree” and “JTreeTable”. There was an article/tutorial a very long time ago on the JDC, or swing-pages, or one of the other semi-official java places about implementing a file-system-browser by combining Table and Tree. So, it’s probably exactly what you want :).

Whenever I need something similar, I just go and look up that article/tutorial/etc. I don’t think it’s part of any of the Swing trails though I could be wrong…

It was on “The Swing Connection”: http://java.sun.com/products/jfc/tsc/articles/treetable1/

Nice! It looks much more useful than I had imagined.

Not that this site is hard to find, but it taught me a lot about getting Swing to jump through hoops ( despite being low on comments ).

http://www2.gol.com/users/tame/swing/examples/SwingExamples.html

I have trouble imagining what it would look like ;D

Somebody post pictures please

just click sma’s link. :wink:

FYI a much more detailed and performance-sensitive look at tabletrees (starting with 40 slides on Jtree and Jtable) can be found here:

http://servlet.java.sun.com/javaone/javaone2000/pdfs/TS-1136.pdf

You need to understand quite a bit about standard patterns in order to make sense of the slides, and clearly it would be a LOT easier to follow if you had the text of the presentation, but it’s got some good content in there (and covers the “mutual-selection infinite recursive loop” problem that bites a lot of people in the ass :)).

Hello,

Thanks for the replys. I haven’t made any progress other than getting the editing working a bit. Works not bad though, handy to be able to change values on the fly and see what happens. Anyways, I am in the Navy and just got back from a couple of weeks at sea so I wasn’t ignoring you guys.

Thanks,
Steve