title: Using TreeTable with different root and node types
body: <p><strong>I have the following problem:</strong></p>
  
  <p>I want to have a JTeeTable-like table component except that the roots (classes below) and the nodes of the tree are not of the same type.</p>
  
  <p>For instance, suppose that I have the following classes:</p>
  
  <pre><code>public final class Entry {
  
      private int id;
      private String title;
      private String notes;
  
      private List&lt;SubEntry&gt; subEntryList; /** @see SubEntry*/
  }
  
  
  public final class SubEntry{
      private int id;
      private String title;
      private String notes;
  
  }
  </code></pre>
  
  <p>Although these two class look similar and may motivate for a case for inheritance, <strong>they are NOT related that way</strong>. <em>Think of it as a car with a list of car parts OR  movie with a list of actors.</em></p>
  
  <p>For two weeks now I have been trying to think of a way to present the above visually. I thought of using the JTreeTable component but all the examples I've come are cross show usage when the subentries (nodes??) are of the same type as the entries (leaf??).</p>
  
  <p><strong>My Idea So Far:</strong>
  Seeing that if I use a table, the columns will share the same names, I thought I should use a table and another table as a TableCellRenderer and then support show/hide on double-click of the parent row. </p>
  
  <p>I am not sure how to move forward though...</p>
  
  <p>So, if you have any ideas how I should go about this, please share your ideas.</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>//I finally managed to sort out the tree table model.
  //Below is the snippet of what I have done. 
  
          private List&lt;Entry&gt; root; 
  
          public EntryTreeTableModel(List&lt;Entry&gt; root) { 
                this.root = root;
          } 
  
      public int getChildCount(Object parent) { 
  
        if (parent instanceof List){ 
               return ((ArrayList&lt;Entry&gt;) parent).size(); 
        }else if (parent instanceof Entry){ 
              return ((Entry)parent).getSubEntries().size(); 
        } 
       return 0; 
     }
  
     public Object getChild(Object parent, int index) {
          if (parent instanceof List){
              return ((ArrayList&lt;Entry&gt;) parent).get(index);
          }else if (parent instanceof Entry){
              return ((Entry)parent).getSubEntries().get(index);
          }else if (parent instanceof Entry){
              return ((SubEntry)parent); // Hmmm, this feels wrong. Check later.
          }
              return "...";  // Just to indicate that something went wrong
      }
  </code></pre>
  
  <p><strong>Other methods of follow the same approach</strong></p>
  
  <blockquote>
    <p>Many thanks to all those who shared
    their ideas. Another thank to
    Trashgod...</p>
  </blockquote>