DefaultTreeTableColumnModel

Top  Previous  Next

 

DefaultTreeTableColumnModel provides a default implementation for a TreeTableColumnModel. For not rewriting the code associated to dealing with tree models, we made it extend ObjectTreeTableModel, although the extra 'column' dimension introduced by TreeTableModel is not used as it is not needed. DefaultTreeTableColumnModel uses TableColumns as the user objects of its (DefaultMutableTreeNode) nodes. Additionally, the TreeTableColumnModel methods are actually calls to its MutableTreeTableModel superclass.

 

Note that, when inserting columns, TableColumn's modelIndex attribute must be associated to the table's data model. For example, if you use the no-argument TableColumn constructor, all created columns will bear a model index of 0, thereby referring to the first column in the data model.

 

Example: Use DefaultTreeTableColumnModel to create a three level tree header

 

//group

DefaultTreeTableColumnModel model = new DefaultTreeTableColumnModel();

 

//first level

TableColumn continents = new TableColumn(0);

continents.setHeaderValue("Continents");

Object continentsNode = model.insertColumnInto(continents, null, model.getRoot(), 0);

 

//second level - europe

TableColumn europe = new TableColumn(1);

europe.setHeaderValue("Europe");

Object europeNode = model.insertColumnInto(europe, null, continentsNode, 0);

//second level - america

TableColumn america = new TableColumn(2);

america.setHeaderValue("America");

Object americaNode = model.insertColumnInto(america, null, continentsNode, 1);

//second level - asia

TableColumn asia = new TableColumn(3);

asia.setHeaderValue("Asia");

Object asiaNode = model.insertColumnInto(asia, null, continentsNode, 2);

 

//third level - europe/germany

TableColumn germany = new TableColumn(4);

germany.setHeaderValue("Germany");

Object germanyNode = model.insertColumnInto(germany, null, europeNode, 0);

//third level - europe/uk

TableColumn uk = new TableColumn(5);

uk.setHeaderValue("UK");

Object ukNode = model.insertColumnInto(uk, null, europeNode, 1);

//third level - europe/italy

TableColumn italy = new TableColumn(6);

italy.setHeaderValue("Italy");

Object italyNode = model.insertColumnInto(italy, null, europeNode, 2);

 

//third level - america/USA

TableColumn usa = new TableColumn(7);

usa.setHeaderValue("USA");

Object usaNode = model.insertColumnInto(usa, null, americaNode, 0);

//third level - america/colombia

TableColumn colombia = new TableColumn(8);

colombia.setHeaderValue("Colombia");

Object colombiaNode = model.insertColumnInto(colombia, null, americaNode, 1);

//third level - america/cuba

TableColumn cuba = new TableColumn(9);

cuba.setHeaderValue("Cuba");

Object cubaNode = model.insertColumnInto(cuba, null, americaNode, 2);

 

Note that the int argument passed to the TableColumn constructor is the column index that maps to the column in the table's data model (the TableModel).