Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to: JTable with collapsible JTree in first column and data in the other columns?

I am somewhat lost at this point: I try to create a JTable that is able to hold some kind of a Tree (JTree?) datastructure in the first column followed by data based on the tree Node in the other columns as illustrated in the following image:

enter image description here

That image shows the structure of my JTree. The red lines indicate the table structur that i would need to realize. Each Node in the Tree should be treatet like a single row in that table, etc. I hope it is clear what i try to achieve.

I tried an aproach like it was discussed here: JTable as a JTree Node and here Put JTable in the JTree but that doesn't fit my needs. I also read about the JXTreeTable from the SwingX project but it seems to be very hard to find any usefull examples. Also many links to solutions like this seem to lead to (no longer existing) sun websites and/or beeing redirected to the oracle site...

It would be awesome if someone could lead me into the right direction and/or provide some exmaple code on how to do this (right).

Any help would be appreciated ;).

like image 830
Ulathar Avatar asked Nov 20 '13 12:11

Ulathar


People also ask

How can I tell if a row is selected in JTable?

So you can call table. getSelectionModel(). isSelectionEmpty() to find out if any row is selected.

How add column in JTable in Netbeans?

Right-click the table and select "Properties." The table's properties display, including the columns. You click a column and change the heading to edit the current columns. To add a new column, click "New" and type a heading for the column.

How can count number of rows in JTable?

You can use the getRowCount() method: Returns the number of rows that can be shown in the JTable , given unlimited space. If a RowSorter with a filter has been specified, the number of rows returned may differ from that of the underlying TableModel .

What is the use of JTree in swing?

The JTree class is used to display the tree structured data or hierarchical data. JTree is a complex component. It has a 'root node' at the top most which is a parent for all nodes in the tree. It inherits JComponent class.


1 Answers

Create your own TreeTable component like in the following link : http://www.java2s.com/Code/Java/Swing-Components/JTreeTablecomponent.htm

like image 171
Mister D. Avatar answered Oct 05 '22 17:10

Mister D.