Updated: Displaying a jTable inside another jTable // JTable cellRenderer 6

After some users asking for answers in my past post, I updated the code of the embedded JTable to make it less buggy and more stable.

This is the “new” code:

JTable inside JTable cell

In the above image you can see the result.

Leave a comment

Your email address will not be published. Required fields are marked *

6 thoughts on “Updated: Displaying a jTable inside another jTable // JTable cellRenderer

  • Chris

    Hey Marc — two things. First, you’ve got some rogue HTML leaking into your second dotted-line-box in the code.

    Second, you CAN get events to the inner JTable. I keep the JTables around, and if the embedded.MouseListener sees it’s been clicked on a cell with a JTable, it does a ‘dispatchEvent’ on the sub-table handing it the event.

    Now, if I could just get highlighting/selection to work properly…

  • Marc Nuri

    Hi Chris, first of all thanks for your response.

    What you say its true, you can make your upper table dispatch events to your subsequent jTables. But although you can achieve what you want (partly) its NOT a recommended way of doing things.

    TableCellRenderer doesn’t build a component for each cell in your JTable, that would be very memmory consuming. So if you want to dispatch events to the inner JTables, you must do as you say “keep them around”. The correct/elegant/performance way of doing this is implementing your own TableCellEditor.

    Further reference can be found in this link:

    Sun Bug Database 4136681

  • Harish Sohane


    but i am facing one proble ..

    if i put JTable inside JTable cell….it’s not showing whole table i mean it’s not showing inside table’s column how to do that….plz help me if possible….

  • Cocu

    hey, i implemented this code and noticed that when you populate the data object, the height of the row is determinated by the last String[] and not by the larger one… how do you fix this?

    besides that, i was having trouble trying to read that data from a list and asiging it to the String[] or to the Data[][]… any ideas?

  • Prashanth

    Hi Marc,

    Thank you, the code is perfectly working for me.

    If I try to copy the table data, the embedded cell values are copied as an Object
    i.e. Peter [Ljava.lang.Object;@20785a37 [Ljava.lang.Object;@2d649736 04-abr-2007

    How can i copy the data as it is for embedded cells instead of Objects.