org.jdesktop.swing
Class JTreeTable

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JTable
                  extended byorg.jdesktop.swing.JXTable
                      extended byorg.jdesktop.swing.JTreeTable
All Implemented Interfaces:
Accessible, CellEditorListener, EventListener, ImageObserver, ListSelectionListener, MenuContainer, PipelineListener, Scrollable, Searchable, Serializable, TableColumnModelListener, TableModelListener

public class JTreeTable
extends JXTable

JTreeTable 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 JTreeTable 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 JTreeTable, is to first create a suitable data model for it, and pass that to a JTreeTable constructor, as shown below:

 	TreeTableModel  treeTableModel = new FileSystemModel();	// any TreeTableModel
 	JTreeTable      treeTable = new JTreeTable(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 JTreeTable instances. To access the treetable model, always call getTreeTableModel and setTreeTableModel. JTreeTable 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
 
Nested classes inherited from class javax.swing.JTable
JTable.AccessibleJTable
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class org.jdesktop.swing.JXTable
filters, highlighters, PRINT_MODE_FIT_WIDTH, PRINT_MODE_NORMAL, sorter, TRACE
 
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
JTreeTable()
          Constructs a JTreeTable using a DefaultTreeTableModel.
JTreeTable(TreeTableModel treeModel)
          Constructs a JTreeTable using the specified TreeTableModel.
 
Method Summary
protected  Component applyRenderer(Component component, ComponentAdapter adapter)
          Performs necessary housekeeping before the renderer is actually applied.
 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.
 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.
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.
 boolean getExpandsSelectedPaths()
          Returns the value of the expandsSelectedPaths property.
 boolean getScrollsOnExpand()
          Returns the value of the scrollsOnExpand property.
 boolean getShowsRootHandles()
          Returns the value of the showsRootHandles property.
 TreeTableModel getTreeTableModel()
          Returns the underlying TreeTableModel for this JTreeTable.
 boolean isHierarchical(int column)
          Determines if the specified column contains hierarchical nodes.
 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)
          Overrides superclass version to provide support for cell decorators.
protected  void resetSorter()
          Overrides superclass version to be a no-op.
 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 setColumnMargin(int columnMargin)
          Sets the margin between columns.
 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 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 JTreeTable before invoking the inherited version.
 void setOpenIcon(Icon icon)
          Sets the specified icon as the icon to use for rendering open container nodes.
 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 JTreeTable.
 void setRowHeight(int row, int rowHeight)
          Throws UnsupportedOperationException because variable height rows are not supported.
 void setRowMargin(int rowMargin)
          Overridden to ensure that private renderer state is kept in sync with the state of the component.
 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 setShowHorizontalLines(boolean show)
          Sets whether the table draws horizontal lines between cells.
 void setShowsRootHandles(boolean visible)
          Sets the value of the showsRootHandles property for the tree part.
 void setShowVerticalLines(boolean show)
          Sets whether the table draws vertical lines between cells.
protected  void setSorter(int columnIndex)
          Overrides superclass version to be a no-op.
 void setTreeTableModel(TreeTableModel treeModel)
          Sets the data model for this JTreeTable 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 updateUI()
          Overridden to message super and forward the method to the tree.
 
Methods inherited from class org.jdesktop.swing.JXTable
contentsChanged, convertRowIndexToModel, convertRowIndexToView, createDefaultColumnsFromModel, createDefaultDataModel, getColumnExt, getColumnExt, getColumnMargin, getColumns, getFilters, getHighlighters, getPreferredScrollableViewportSize, getPrintable, getRowCount, getSelectionMode, getSorter, getValueAt, getVisibleRowCount, init, isCellEditable, isPrinting, print, print, print, print, removeColumns, search, search, search, search, search, setFilters, setHighlighters, setTableHeader, setValueAt, setVisibleRowCount, tableChanged
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, createDefaultColumnModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createDefaultTableHeader, createScrollPaneForTable, doLayout, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoCreateColumnsFromModel, getAutoResizeMode, getCellEditor, getCellEditor, getCellRect, getCellRenderer, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getEditingColumn, getEditorComponent, getGridColor, getIntercellSpacing, getModel, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, initializeLocalVars, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, prepareEditor, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnModel, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setPreferredScrollableViewportSize, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionModel, setShowGrid, setSurrendersFocusOnKeystroke, setUI, sizeColumnsToFit, unconfigureEnclosingScrollPane, valueChanged
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JTreeTable

public JTreeTable()
Constructs a JTreeTable using a DefaultTreeTableModel.


JTreeTable

public JTreeTable(TreeTableModel treeModel)
Constructs a JTreeTable using the specified TreeTableModel.

Parameters:
treeModel - model for the JTreeTable
Method Detail

resetSorter

protected void resetSorter()
Overrides superclass version to be a no-op.

Overrides:
resetSorter in class JXTable

setSorter

protected void setSorter(int columnIndex)
Overrides superclass version to be a no-op.

Overrides:
setSorter in class JXTable

setShowHorizontalLines

public void setShowHorizontalLines(boolean show)

Sets whether the table draws horizontal lines between cells. It draws the lines if show is true; otherwise it doesn't. By default, a table draws the lines.

If you want the lines to be drawn, make sure that the row margin or horizontal intercell spacing is greater than zero.

Parameters:
show - true, if horizontal lines should be drawn; false, if lines should not be drawn
See Also:
getShowHorizontalLines, setRowMargin, setIntercellSpacing

setShowVerticalLines

public void setShowVerticalLines(boolean show)

Sets whether the table draws vertical lines between cells. It draws the lines if show is true; otherwise it doesn't. By default, a table draws the lines.

If you want the lines to be drawn, make sure that the column margin or vertical intercell spacing is greater than zero.

Parameters:
show - true, if vertical lines should be drawn; false, if lines should not be drawn
See Also:
getShowVerticalLines, setColumnMargin, setInte