TreeTableColumnModel

Top  Previous  Next

 

TreeTableColumnModel defines the structure of a hierarchical column model. TreeTableColumnModel extends javax.swing.tree.TreeModel and defines three extra methods for retrieving, adding and removing table columns. These are:

 

public TableColumn getColumn(Object node): Returns the table column at the specified node.

public Object insertColumnInto(TableColumn aColumn, Object columnNode, Object parentNode, int index): Inserts a table column at the node specified by columnNode, whose parent is parentNode and index is the child location in the parent node. The columnNode parameter is optional, by setting this to null, TreeTableColumnModel should create a new node for the supplied column. The object returned is the newly created node, or the columnNode object passed as a parameter to the method.

public void removeColumnFrom(Object node): Removes the node, and thereby the column, from the model.

 

Note that you can install TreeModelListeners to be notified when a column was added, removed, or changed:

 

TreeTableColumnModel.addTreeModelListener(new javax.swing.event.TreeModelListener() {

       public void treeNodesChanged(javax.swing.event.TreeModelEvent e) {

               

       }

       public void treeNodesInserted(javax.swing.event.TreeModelEvent e) {

               Object[] children = e.getChildren();

               if (children == null) return;

               for (int i = 0; i < children.length; i++) {

                       TableColumn tc = treeColumnModel.getColumn(children[i]);

                       //column tc was added

               }

       }

       public void treeNodesRemoved(javax.swing.event.TreeModelEvent e) {

               

       }

       public void treeStructureChanged(javax.swing.event.TreeModelEvent e) {

               

       }

});