public JTreeTable(TreeTableModel treeTableModel) : base() { // Create the tree. It will be used as a renderer and editor. tree = new JTreeTable.TreeTableCellRenderer(this, treeTableModel); // Install a tableModel representing the visible rows in the tree. base.SetModel(new TreeTableModelAdapter(treeTableModel, tree)); // Force the JTable and JTree to share their row selection models. JTreeTable.ListToTreeSelectionModelWrapper selectionWrapper = new JTreeTable.ListToTreeSelectionModelWrapper(this); tree.SetSelectionModel(selectionWrapper); SetSelectionModel(selectionWrapper.GetListSelectionModel()); // Install the tree editor renderer and editor. SetDefaultRenderer(typeof(TreeTableModel), tree); SetDefaultEditor(typeof(TreeTableModel), new JTreeTable.TreeTableCellEditor(this)); // No grid. SetShowGrid(false); // No intercell spacing SetIntercellSpacing(new Dimension(0, 0)); // And update the height of the trees row to match that of // the table. if (tree.GetRowHeight() < 1) { // Metal looks better like this. SetRowHeight(18); } }
public TreeTableModelAdapter(TreeTableModel treeTableModel, JTree tree) { this.tree = tree; this.treeTableModel = treeTableModel; tree.AddTreeExpansionListener(new _TreeExpansionListener_65(this)); // Don't use fireTableRowsInserted() here; the selection model // would get updated twice. // Install a TreeModelListener that can update the table when // tree changes. We use delayedFireTableDataChanged as we can // not be guaranteed the tree will have finished processing // the event before us. treeTableModel.AddTreeModelListener(new _TreeModelListener_80(this)); }