org.jdesktop.swingx
Class JXTreeTable

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JTable
                  extended by org.jdesktop.swingx.JXTable
                      extended by org.jdesktop.swingx.JXTreeTable
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, EventListener, Accessible, CellEditorListener, ListSelectionListener, TableColumnModelListener, TableModelListener, Scrollable, TableColumnModelExtListener

public class JXTreeTable
extends JXTable

JXTreeTable is a specialized table consisting of a single column in which to display hierarchical data, and any number of other columns in which to display regular data. The interface for the data model used by a JXTreeTable is TreeTableModel. It extends the TreeModel interface to allow access to cell data by column indices within each node of the tree hierarchy.

The most straightforward way create and use a JXTreeTable, is to first create a suitable data model for it, and pass that to a JXTreeTable constructor, as shown below:

  TreeTableModel  treeTableModel = new FileSystemModel(); // any TreeTableModel
  JXTreeTable     treeTable = new JXTreeTable(treeTableModel);
  JScrollPane     scrollpane = new JScrollPane(treeTable);
 
See JTable for an explanation of why putting the treetable inside a scroll pane is necessary.

A single treetable model instance may be shared among more than one JXTreeTable instances. To access the treetable model, always call getTreeTableModel and setTreeTableModel. JXTreeTable wraps the supplied treetable model inside a private adapter class to adapt it to a TableModel. Although the model adapter is accessible through the getModel method, you should avoid accessing and manipulating it in any way. In particular, each model adapter instance is tightly bound to a single table instance, and any attempt to share it with another table (for example, by calling setModel) will throw an IllegalArgumentException!

See Also:
Serialized Form

Nested Class Summary
protected static class JXTreeTable.TreeTableDataAdapter
           
 class JXTreeTable.TreeTableHacker
          Temporary class to have all the hacking at one place.
 class JXTreeTable.TreeTableHackerExt
          Note: currently this class looks a bit funny (only overriding the hit decision method).
 class JXTreeTable.TreeTableHackerExt2
          Patch for #471-swingx: no selection on click in hierarchical column outside of node-text.
protected static class JXTreeTable.TreeTableModelAdapter
           
 
Nested classes/interfaces inherited from class org.jdesktop.swingx.JXTable
JXTable.BooleanEditor, JXTable.GenericEditor, JXTable.NumberEditor, JXTable.TableAdapter, JXTable.TableRolloverController<T extends JTable>, JXTable.TableSearchable
 
Nested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable, JTable.PrintMode
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static String DRAG_HACK_FLAG_KEY
          Key for clientProperty to decide whether to apply hack around #168-jdnc.
 
Fields inherited from class org.jdesktop.swingx.JXTable
compoundHighlighter, dataAdapter, editorRemover, filters, FOCUS_NEXT_COMPONENT, FOCUS_PREVIOUS_COMPONENT, HORIZONTALSCROLL_ACTION_COMMAND, isXTableRowHeightSet, MATCH_HIGHLIGHTER, PACKALL_ACTION_COMMAND, PACKSELECTED_ACTION_COMMAND, resetDefaultTableCellRendererHighlighter, searchable, selectionMapper, UIPREFIX, USE_DTCR_COLORMEMORY_HACK
 
Fields inherited from class javax.swing.JTable
AUTO_RESIZE_ALL_COLUMNS, AUTO_RESIZE_LAST_COLUMN, AUTO_RESIZE_NEXT_COLUMN, AUTO_RESIZE_OFF, AUTO_RESIZE_SUBSEQUENT_COLUMNS, autoCreateColumnsFromModel, autoResizeMode, cellEditor, cellSelectionEnabled, columnModel, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, showHorizontalLines, showVerticalLines, tableHeader
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JXTreeTable()
          Constructs a JXTreeTable using a DefaultTreeTableModel.
JXTreeTable(TreeTableModel treeModel)
          Constructs a JXTreeTable using the specified TreeTableModel.
 
Method Summary
 void addTreeExpansionListener(TreeExpansionListener tel)
          Adds a listener for TreeExpansion events.
 void addTreeSelectionListener(TreeSelectionListener tsl)
          Adds a listener for TreeSelection events.
 void addTreeWillExpandListener(TreeWillExpandListener tel)
          Adds a listener for TreeWillExpand events.
protected  void adjustTableRowHeight(int treeRowHeight)
          Forwards treeRowHeight to table.
protected  void adjustTreeRowHeight(int tableRowHeight)
          Forwards tableRowHeight to tree.
protected  Component applyRenderer(Component component, ComponentAdapter adapter)
          Performs configuration of the tree's renderer if the adapter's column is the hierarchical column, does nothing otherwise.
 void clearSelection()
          Overridden to ensure that private renderer state is kept in sync with the state of the component.
 void collapseAll()
          Collapses all nodes in the treetable.
 void collapsePath(TreePath path)
          Collapses the node at the specified path in the treetable.
 void collapseRow(int row)
          Collapses the row in the treetable.
protected  SelectionMapper createSelectionMapper()
          Fix for #745-swingx: remove static selectionMaper.
protected  JXTreeTable.TreeTableHacker createTreeTableHacker()
           
 boolean editCellAt(int row, int column, EventObject e)
          Overriden to invoke repaint for the particular location if the column contains the tree.
 void expandAll()
          Expands all nodes in the treetable.
 void expandPath(TreePath path)
          Expands the the node at the specified path in the treetable.
 void expandRow(int row)
          Expands the specified row in the treetable.
 TableCellEditor getCellEditor(int row, int column)
          Returns an appropriate editor for the cell specified by row and column.
 TableCellRenderer getCellRenderer(int row, int column)
          Returns an appropriate renderer for the cell specified by this row and column. If the TableColumn for this column has a non-null renderer, returns that. If not, finds the class of the data in this column (using getColumnClass) and returns the default renderer for this type of data.

Note: Throughout the table package, the internal implementations always use this method to provide renderers so that this default behavior can be safely overridden by a subclass.

protected  ComponentAdapter getComponentAdapter()
          Returns the adapter that knows how to access the component data model.
 int getEditingRow()
          Overridden to provide a workaround for BasicTableUI anomaly.
 Enumeration<?> getExpandedDescendants(TreePath parent)
          Returns an Enumeration of the descendants of the path parent that are currently expanded.
 boolean getExpandsSelectedPaths()
          Returns the value of the expandsSelectedPaths property.
 int getHierarchicalColumn()
          Returns the index of the hierarchical column.
 TreePath getPathForLocation(int x, int y)
          Returns the TreePath for a given x,y location.
 TreePath getPathForRow(int row)
          Returns the TreePath for a given row.
 int getRowForPath(TreePath path)
          Returns the row for a given TreePath.
 boolean getScrollsOnExpand()
          Returns the value of the scrollsOnExpand property.
 SelectionMapper getSelectionMapper()
          Overridden to return a do-nothing mapper.
 boolean getShowsRootHandles()
          Returns the value of the showsRootHandles property.
 String getStringAt(int row, int column)
          Returns the string representation of the cell value at the given position.
 int getToggleClickCount()
          Returns the number of mouse clicks needed to expand or close a node.
 String getToolTipText(MouseEvent event)
          Overrides JComponent's getToolTipText method in order to allow the renderer's tips to be used if it has text set.
 TreeCellRenderer getTreeCellRenderer()
           
 TreeSelectionModel getTreeSelectionModel()
          Returns the selection model for the tree portion of the this treetable.
protected  JXTreeTable.TreeTableHacker getTreeTableHacker()
           
 TreeTableModel getTreeTableModel()
          Returns the underlying TreeTableModel for this JXTreeTable.
protected  boolean hackAroundDragEnabled(MouseEvent me)
          decides whether we want to apply the hack for #168-jdnc.
 boolean isCollapsed(int row)
          Returns true if the node at the specified display row is collapsed.
 boolean isCollapsed(TreePath path)
          Returns true if the node identified by path is currently collapsed, this will return false if any of the values in path are currently not being displayed.
 boolean isExpanded(int row)
          Returns true if the node at the specified display row is currently expanded.
 boolean isExpanded(TreePath path)
          Returns true if the node identified by path is currently expanded.
 boolean isHierarchical(int column)
          Determines if the specified column is defined as the hierarchical column.
 boolean isLargeModel()
          Returns true if the tree is configured for a large model.
 boolean isOverwriteRendererIcons()
          Returns a boolean indicating whether the per-tree icons should be copied to the renderer on setTreeCellRenderer.
 boolean isRootVisible()
          Returns true if the root node of the tree is displayed.
 boolean isVisible(TreePath path)
          Returns true if the value identified by path is currently viewable, which means it is either the root or all of its parents are expanded.
 Component prepareRenderer(TableCellRenderer renderer, int row, int column)
          Returns the decorated Component used as a stamp to render the specified cell.
protected  void processMouseEvent(MouseEvent e)
          Overridden to enable hit handle detection a mouseEvent which triggered a expand/collapse.
 void removeTreeExpansionListener(TreeExpansionListener tel)
          Removes a listener for TreeExpansion events.
 void removeTreeSelectionListener(TreeSelectionListener tsl)
          Removes a listener for TreeSelection events.
 void removeTreeWillExpandListener(TreeWillExpandListener tel)
          Removes a listener for TreeWillExpand events.
 void scrollPathToVisible(TreePath path)
          Makes sure all the path components in path are expanded (except for the last path component) and scrolls so that the node identified by the path is displayed.
 void setClosedIcon(Icon icon)
          Sets the specified icon as the icon to use for rendering closed container nodes.
 void setCollapsedIcon(Icon icon)
          Sets the specified icon as the icon to use for rendering collapsed nodes.
 void setExpandedIcon(Icon icon)
          Sets the specified icon as the icon to use for rendering expanded nodes.
 void setExpandsSelectedPaths(boolean expand)
          Sets the value of the expandsSelectedPaths property for the tree part.
 void setFilters(FilterPipeline pipeline)
          overridden to do nothing.
 void setLargeModel(boolean newValue)
          Specifies whether the UI should use a large model.
 void setLeafIcon(Icon icon)
          Sets the specified icon as the icon to use for rendering leaf nodes.
 void setModel(TableModel tableModel)
          Overrides superclass version to make sure that the specified TableModel is compatible with JXTreeTable before invoking the inherited version.
 void setOpenIcon(Icon icon)
          Sets the specified icon as the icon to use for rendering open container nodes.
 void setOverwriteRendererIcons(boolean overwrite)
          Property to control whether per-tree icons should be copied to the renderer on setTreeCellRenderer.
 void setRootVisible(boolean visible)
          Determines whether or not the root node from the TreeModel is visible.
 void setRowHeight(int rowHeight)
          Sets the row height for this JXTreeTable and forwards the row height to the renderering tree.
 void setRowHeight(int row, int rowHeight)
          Throws UnsupportedOperationException because variable height rows are not supported.
 void setScrollsOnExpand(boolean scroll)
          Sets the value of the scrollsOnExpand property for the tree part.
 void setSelectionMode(int mode)
          Overridden to ensure that private renderer state is kept in sync with the state of the component.
 void setShowsRootHandles(boolean visible)
          Sets the value of the showsRootHandles property for the tree part.
 void setSortable(boolean sortable)
          overridden to do nothing.
 void setToggleClickCount(int clickCount)
          Sets the number of mouse clicks before a node will expand or close.
 void setTreeCellRenderer(TreeCellRenderer cellRenderer)
          Sets the specified TreeCellRenderer as the Tree cell renderer.
 void setTreeTableModel(TreeTableModel treeModel)
          Sets the data model for this JXTreeTable to the specified TreeTableModel.
 void sizeColumnsToFit(int resizingColumn)
          Overriden to invoke supers implementation, and then, if the receiver is editing a Tree column, the editors bounds is reset.
 void tableChanged(TableModelEvent e)
          additionally updates filtered state.
 
Methods inherited from class org.jdesktop.swingx.JXTable
addHighlighter, adjustComponentOrientation, adminSetRowHeight, columnMarginChanged, columnPropertyChange, columnRemoved, columnSelectionChanged, configureColumnControl, configureEnclosingScrollPane, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnControl, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultEditors, createDefaultRenderers, createDefaultTableHeader, createHighlighterChangeListener, createLinkController, createPipelineListener, createRolloverProducer, doLayout, getColumn, getColumnControl, getColumnCount, getColumnExt, getColumnExt, getColumnFactory, getColumnMargin, getColumns, getColumns, getComponentAdapter, getFillsViewportHeight, getFilterPipelineListener, getFilters, getHighlighterChangeListener, getHighlighters, getLinkController, getNewDefaultRenderer, getPreferredScrollableViewportSize, getRowCount, getRowModelMapper, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getSearchable, getSelectionMode, getSortController, getSortedColumn, getSortOrder, getSortOrder, getUIString, getUIString, getValueAt, getVisibleColumnCount, getVisibleRowCount, initializeColumnPreferredWidth, initializeColumnWidths, isAutoStartEditOnKeyStroke, isCellEditable, isColumnControlVisible, isDataChanged, isEditable, isFocusCycleRoot, isHorizontalScrollEnabled, isRolloverEnabled, isRowHeightEnabled, isSortable, isSortable, isSortable, isStructureChanged, isTerminateEditOnFocusLost, isUpdate, packAll, packColumn, packColumn, packSelected, packTable, prepareEditor, removeEditor, removeHighlighter, removeNotify, resetDefaultTableCellRendererColors, resetSortOrder, rowAtPoint, scrollCellToVisible, scrollColumnToVisible, scrollRowToVisible, setAutoResizeMode, setAutoStartEditOnKeyStroke, setColumnControl, setColumnControlVisible, setColumnFactory, setColumnMargin, setColumnSequence, setComponentOrientation, setEditable, setFillsViewportHeight, setHighlighters, setHorizontalScrollEnabled, setLocale, setPreferredScrollableViewportSize, setRolloverEnabled, setRowHeightEnabled, setSearchable, setSelectionBackground, setSelectionForeground, setSelectionModel, setShowGrid, setShowGrid, setSortOrder, setSortOrder, setTerminateEditOnFocusLost, setValueAt, setVisibleColumnCount, setVisibleRowCount, shouldSortOnChange, toggleSortOrder, toggleSortOrder, transferFocus, transferFocusBackward, updateHighlighterUI, updateHorizontalAction, updateLocaleActionState, updateLocaleState, updateOnFilterContentChanged, updateRowHeightUI, updateUI, updateViewSizeSequence
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, columnAdded, columnAtPoint, columnMoved, convertColumnIndexToModel, convertColumnIndexToView, createDefaultDataModel, createDefaultSelectionModel, createScrollPaneForTable, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoResizeMode, getCellEditor, getCellRect, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getEditingColumn, getEditorComponent, getGridColor, getIntercellSpacing, getModel, getPrintable, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getUI, getUIClassID, initializeLocalVars, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeRowSelectionInterval, resizeAndRepaint, selectAll, setAutoCreateColumnsFromModel, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, sizeColumnsToFit, unconfigureEnclosingScrollPane, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents,