eu.beesoft.gaia.swing
Class JTreeTable

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 eu.beesoft.gaia.swing.JZebraTable
                      extended by eu.beesoft.gaia.swing.JTreeTable
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.CellEditorListener, javax.swing.event.ListSelectionListener, javax.swing.event.TableColumnModelListener, javax.swing.event.TableModelListener, javax.swing.Scrollable
Direct Known Subclasses:
GanttTreeTable

public class JTreeTable
extends JZebraTable

A JTreeTable is a combination of a JTree and a JTable - a component capable of both expanding and contracting rows, as well as showing multiple columns of data.

This component always displays a tree in the first column and the additional data in the next columns. You can see its usage in a very simple example of the directory tree.

This component has the next features:

Note: The code in this class is derived from the source from the JTreeTable article that can be found at: http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JTable
javax.swing.JTable.AccessibleJTable, javax.swing.JTable.PrintMode
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
Fields inherited from class eu.beesoft.gaia.swing.JZebraTable
DEFAULT
 
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, dataModel, defaultEditorsByColumnClass, defaultRenderersByColumnClass, editingColumn, editingRow, editorComp, gridColor, preferredViewportSize, rowHeight, rowMargin, rowSelectionAllowed, selectionBackground, selectionForeground, selectionModel, 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()
          Creates a new instance of the JTreeTable with a default (null-root) model.
JTreeTable(TreeTableModel model)
          Creates a new instance of the JTreeTable and sets given model as its model.
JTreeTable(TreeTableModel model, javax.swing.table.TableColumnModel columnModel)
          Creates a new instance of the JTreeTable and sets given model as its data model and columnModel as its column model .
JTreeTable(TreeTableNode root)
          Creates a new instance of the JTreeTable.
JTreeTable(TreeTableNode root, java.lang.String[] columnNames)
          Creates a new instance of the JTreeTable.
 
Method Summary
protected  TreeTableModel createDefaultModel()
          Creates instance of TreeTableModel with null root node.
 int getEditingRow()
          Workaround for BasicTableUI anomaly.
 TreeTableNode getNodeForRow(int row)
          Returns the node displayed at queried row.
 JZebraTree getTree()
          Returns the tree that is being shared between the model.
 TreeTableModel getTreeTableModel()
          Returns this JTreeTable model.
 void setRowHeight(int rowHeight)
          Overridden to pass the new rowHeight to the tree.
 void setTreeTableModel(TreeTableModel model)
          Sets new JTreeTable model.
protected  void tableDataChanged()
          Invoked after all the pending events have been processed Empty implementation.
 void updateUI()
          Overridden to message super and forward the method to the tree.
 
Methods inherited from class eu.beesoft.gaia.swing.JZebraTable
addColumn, createDefaultColumnModel, createDefaultTableHeader, createScrollPane, getAlternateBackground, getBackgroundForRow, getColumnByModelIndex, getColumnCount, getColumnIndex, getColumns, getDefaultAlternateBackground, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getShowHorizontalLines, getShowVerticalLines, isColumnVisible, pack, packColumn, paintComponent, prepareEditor, prepareRenderer, setAllColumnsVisible, setAlternateBackground, setColumnModel, setColumnVisible, setShowGrid, setShowHorizontalLines, setShowVerticalLines, setVisibleRowCount
 
Methods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, clearSelection, columnAdded, columnAtPoint, columnMarginChanged, columnMoved, columnRemoved, columnSelectionChanged, configureEnclosingScrollPane, convertColumnIndexToModel, convertColumnIndexToView, createDefaultColumnsFromModel, createDefaultDataModel, createDefaultEditors, createDefaultRenderers, createDefaultSelectionModel, createScrollPaneForTable, doLayout, editCellAt, 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, getPreferredScrollableViewportSize, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getScrollableBlockIncrement, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getSurrendersFocusOnKeystroke, getTableHeader, getToolTipText, getUI, getUIClassID, getValueAt, changeSelection, initializeLocalVars, isCellEditable, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeEditor, removeNotify, removeRowSelectionInterval, resizeAndRepaint, rowAtPoint, selectAll, setAutoCreateColumnsFromModel, setAutoResizeMode, setCellEditor, setCellSelectionEnabled, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDefaultRenderer, setDragEnabled, setEditingColumn, setEditingRow, setGridColor, setIntercellSpacing, setModel, setPreferredScrollableViewportSize, setRowHeight, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionBackground, setSelectionForeground, setSelectionMode, setSelectionModel, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setValueAt, sizeColumnsToFit, sizeColumnsToFit, tableChanged, 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, paintImmediately, paintImmediately, print, printAll, printBorder, printComponent, printChildren, processComponentKeyEvent, processKeyEvent, processMouseEvent, 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, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, checkImage, checkImage, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, 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()
Creates a new instance of the JTreeTable with a default (null-root) model.


JTreeTable

public JTreeTable(TreeTableNode root)
Creates a new instance of the JTreeTable. Creates a new instance of TreeTableModel and sets the given root as its root node.

Parameters:
root - - the root node

JTreeTable

public JTreeTable(TreeTableNode root,
                  java.lang.String[] columnNames)
Creates a new instance of the JTreeTable. Creates a new instance of TreeTableModel and sets the given root as its root node and columnNames as the column names.

Parameters:
root - - the root node
columnNames - - the names (labels) of columns in JTreeTable

JTreeTable

public JTreeTable(TreeTableModel model)
Creates a new instance of the JTreeTable and sets given model as its model.

Parameters:
model - - the new treetable model

JTreeTable

public JTreeTable(TreeTableModel model,
                  javax.swing.table.TableColumnModel columnModel)
Creates a new instance of the JTreeTable and sets given model as its data model and columnModel as its column model .

Parameters:
model - - the new treetable model
columnModel - - the new treetable column model
Method Detail

createDefaultModel

protected TreeTableModel createDefaultModel()
Creates instance of TreeTableModel with null root node.

Returns:
newly created model

getTreeTableModel

public TreeTableModel getTreeTableModel()
Returns this JTreeTable model.

Returns:
treetable model

setTreeTableModel

public void setTreeTableModel(TreeTableModel model)
Sets new JTreeTable model.

Parameters:
model - - a model to set

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 javax.swing.JTable

getEditingRow

public int getEditingRow()
Workaround for BasicTableUI anomaly. Make sure the UI never tries to paint the editor. The UI currently uses different techniques to paint the renderers and editors and 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 javax.swing.JTable

setRowHeight

public void setRowHeight(int rowHeight)
Overridden to pass the new rowHeight to the tree.

Overrides:
setRowHeight in class javax.swing.JTable
Parameters:
rowHeight - - a new row height to set

getTree

public JZebraTree getTree()
Returns the tree that is being shared between the model.

Returns:
tree

getNodeForRow

public TreeTableNode getNodeForRow(int row)
Returns the node displayed at queried row.

Parameters:
row - - an integer specifying a row
Returns:
node at given row

tableDataChanged

protected void tableDataChanged()
Invoked after all the pending events have been processed Empty implementation.