How can we add a JTable to another JTable?
Suppose I have a JTable with 10 rows and if I double click on a row, that row should be vanished and a new JTable should be inserted in that entire row. I tried to insert the number of rows required, and I am removing the row selected by calling
((Defaul开发者_JAVA百科tTableModel)table.getModel()).getDataVector().removeElementAt(row+insertedNumberOfRows)
Is there any other way to do add a JTable as a component in that entire row?
You can't add a JTable
inside another JTable
. If you want to show a new child table (detail) when clicking on a row of the parent (master) table, listen the double-click in the cell, then remove the JTable
from the containter panel, create the new one with the new rows to show and add to the container panel. Be careful with pack()
and validate()
as you remove and add components lively.
精彩评论