Class JTreeTable

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, RowSorterListener, TableColumnModelListener, TableModelListener, Scrollable

public class JTreeTable extends JTable
This example shows how to create a simple JTreeTable component, by using a JTree as a renderer (and editor) for the cells in a particular column in the JTable.
Version:
1.2 10/27/98
See Also:
  • Field Details

  • Constructor Details

  • Method Details

    • updateUI

      public void updateUI()
      Overridden to message super and forward the method to the tree. Since the tree is not actually in the component hierarchy it will never receive this unless we forward it in this manner.
      Overrides:
      updateUI in class JTable
    • getEditingRow

      public int getEditingRow()
      Workaround for BasicTableUI anomaly. Make sure the UI never tries to resize the editor. The UI currently uses different techniques to paint the renderers and editors; overriding setBounds() below is not the right thing to do for an editor. Returning -1 for the editing row in this case, ensures the editor is never painted.
      Overrides:
      getEditingRow in class JTable
    • sizeColumnsToFit

      public void sizeColumnsToFit(int resizingColumn)
      This is overridden to invoke super's implementation, and then, if the receiver is editing a Tree column, the editor's bounds is reset. The reason we have to do this is because JTable doesn't think the table is being edited, as getEditingRow returns -1, and therefore doesn't automatically resize the editor for us.
      Overrides:
      sizeColumnsToFit in class JTable
    • setRowHeight

      public void setRowHeight(int rowHeight)
      Overridden to pass the new rowHeight to the tree.
      Overrides:
      setRowHeight in class JTable
    • getTree

      public JTree getTree()
      Returns the tree that is being shared between the model.
    • editCellAt

      public boolean editCellAt(int row, int column, EventObject e)
      Overridden to invoke repaint for the particular location if the column contains the tree. This is done as the tree editor does not fill the bounds of the cell, we need the renderer to paint the tree in the background, and then draw the editor over it.
      Overrides:
      editCellAt in class JTable
    • isPathEditable

      protected boolean isPathEditable(TreePath pPath)
      Determine if a specific tree node is editable. Returns true by default.