TreeTableColumnModelAdapter

Top  Previous  Next

 

TreeTableColumnModelAdapter is the column model used by TreeTableHeader. Its default implementation is a DefaultTreeTableColumnModelAdapter. TreeTableColumnModelAdapter maintains an instance to the TreeTableColumnModel containing the column data, while it exposes, with the help of a JTree, the expanded columns to the table. The collapsed columns remain hidden and are made available to the table upon tree expansion events.

 

DefaultTreeTableColumnModelAdapter has two constructors:

 

public DefaultTreeTableColumnModelAdapter(): Default, no-argument, a TreeTableColumnModel is created with protected TreeTableColumnModel createDefaultTreeColumnModel().

 

public DefaultTreeTableColumnModelAdapter(TreeTableColumnModel treeTableModel): assigns the TreeTableColumnModel at construction time.

 

The TreeTableColumnModel can be assigned any time using the method:

 

public void setTreeTableColumnModel(TreeTableColumnModel model)

 

Note that TreeTableHeader will create a DefaultTreeTableColumnModelAdapter upon initialization.

 

TreeTableColumnModelAdapter also has a JTree which is used to find out which column nodes are expanded or collapsed. You can retrieve the JTree variable with the method:

 

public JTree getTree()

 

The JTree can then be used to expand or collapse rows or tree paths programatically:

 

JTree tree = TreeTableColumnModelAdapter.getTree();

tree.expandRow(1);

 

You can also install TreeExpansionListeners to be notified after a column has been expanded:

 

tree.addTreeExpansionListener(new TreeExpansionListener() {

       public void treeExpanded(TreeExpansionEvent event) {

               TreePath path = event.getPath();

               Object node = path.getLastPathComponent();

               //supposing model is the TreeTableColumnModel

               TableColumn column = model.getColumn(node); //column has been expanded

       }

       public void treeCollapsed(TreeExpansionEvent event) {

               

       }

});

 

Also, to find the node at a specific row of the tree, you can use DefaultTreeTableColumnModelAdapter's method:

 

public Object nodeForRow(int rowIndex)