te an EventList of data EventList myEventList = ... // create a TreeList which uses a TreeFormat object to infer a hierarchy for each element in myEventList TreeList treeList = new TreeList(myEventList, new MyTreeFormat()); // create a JTable that displays the contents of treeList in a tabular format EventTableModel myTableModel = new EventTableModel(treeList, new MyTableFormat()); JTable myTable = new JTable(myTableModel); // make the 3rd table column a hierarchical column to create a TreeTable TreeTableSupport.install(myTable, treeList, 2); In order to achieve all of the treetable behaviours, the following occurs when {@link #install} is called:
- a {@link TreeTableCellRenderer} will be installed on the hierarchical{@link TableColumn}. It wraps any {@link TableCellRenderer} previouslyinstalled on the {@link TableColumn}, or if none was present, a DefaultTableCellRenderer. The delegate renderer can be changed at any time using {@link #setDelegateRenderer}.
- a {@link TreeTableCellEditor} will be installed on the hierarchical{@link TableColumn}. It wraps any {@link TableCellEditor} previouslyinstalled on the {@link TableColumn}, or if none was present, a DefaultCellEditor. The delegate editor can be changed at any time using {@link #setDelegateEditor}.
- the UI Delegate's MouseListener will be decorated with extra functionality that detects clicks overtop of the expand/collapse icon and reacts accordingly by expanding/collapsing the hierarchy. In these cases the normal mechanism for handling clicks over the table is circumvented and thus cell edits and/or row selection changes are not honoured.
Customizing TreeTableSupport After installing the basic TreeTableSupport, its specific behaviour can be refined by setting properties on the instance of TreeTableSupport returned by the {@link #install} method. Below are descriptions of some ofthe available customizations.
Left & Right Arrow Keys
Within a treetable there is ambiguity about the functions performed by the left and right arrow keys. Tables normally use them to advance cell focus to the left or right while trees commonly use them to expand or collapse hierarchies. What behaviour is desirable for any given treetable? By default, TreeTableSupport assumes the table-style behaviour but that can be adjusted to the tree-style behaviour calling {@link #setArrowKeyExpansionEnabled} with an argument of true.Generally speaking, tree-style behaviour is preferrable when the treetable is readonly.
Displaying Expander Buttons
{@link TreeList} draws a distinction between three unique situationsregarding the display of the expander button for a given tree node, N:
@author James Lemieux