Class JXTreeTable
- All Implemented Interfaces:
ImageObserver,MenuContainer,Serializable,EventListener,Accessible,CellEditorListener,ListSelectionListener,RowSorterListener,TableColumnModelListener,TableModelListener,Scrollable,TableColumnModelExtListener
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!
Note:
This implementation is basically as hacky as the very first version more than a decaded ago: the renderer of the hierarchical column is a JXTree which is trickst into painting a single row at the position of the table cell. TreeModel changes must be adapted to TableModel changes after the tree received them, that is the TableModel events are asynchronous as compared to their base trigger. As a consequence, the adapted TableModel doesn't play nicely when shared in other J/X/Tables (f.i. used as rowHeader - see http://java.net/jira/browse/SWINGX-1529)
- Author:
- Philip Milne, Scott Violet, Ramesh Gupta
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classprotected static classclassTemporary class to have all the hacking at one place.classNote: currently this class looks a bit funny (only overriding the hit decision method).classPatch for #471-swingx: no selection on click in hierarchical column if outside of node-text.classA more (or less, depending in pov :-) aggressiv hacker.classThis class extends TreeTableHackerExt instead of TreeTableHackerExt3 so as to serve as a clue that it is a complete overhaul and looking in TreeTableHackerExt2 and TreeTableHackerExt3 for methods to change the behavior will do you no good.classstatic classAdapt TreeTableCellRenderer to TableModel used in ctor JXTreeTable(TreeTableCellRenderer renderer)Nested classes/interfaces inherited from class org.jdesktop.swingx.JXTable
JXTable.BooleanEditor, JXTable.GenericEditor, JXTable.NumberEditor, JXTable.TableAdapterNested classes/interfaces inherited from class javax.swing.JTable
JTable.AccessibleJTable, JTable.DropLocation, JTable.PrintModeNested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringKey for clientProperty to decide whether to apply hack around #168-jdnc.static final StringKey for clientProperty to decide whether to apply hack around #766-swingx.Fields inherited from class org.jdesktop.swingx.JXTable
compoundHighlighter, dataAdapter, editorRemover, filteredRowCountChanged, FOCUS_NEXT_COMPONENT, FOCUS_PREVIOUS_COMPONENT, forceRevalidate, HORIZONTALSCROLL_ACTION_COMMAND, isXTableRowHeightSet, MATCH_HIGHLIGHTER, PACKALL_ACTION_COMMAND, PACKSELECTED_ACTION_COMMAND, resetDefaultTableCellRendererHighlighter, searchable, UIPREFIX, USE_DTCR_COLORMEMORY_HACKFields 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, tableHeaderFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH -
Constructor Summary
ConstructorsModifierConstructorDescriptionConstructs a JXTreeTable using aDefaultTreeTableModel.protectedJXTreeTable(JXTreeTable.TreeTableCellRenderer renderer) Constructs aJXTreeTableusing the specifiedJXTreeTable.TreeTableCellRenderer.JXTreeTable(TreeTableModel treeModel) Constructs a JXTreeTable using the specifiedTreeTableModel. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a listener forTreeExpansionevents.voidAdds a listener forTreeSelectionevents.voidAdds a listener forTreeWillExpandevents.protected voidadjustTableRowHeight(int treeRowHeight) Forwards treeRowHeight to table.protected voidadjustTreeRowHeight(int tableRowHeight) Forwards tableRowHeight to tree.protected ComponentapplyRenderer(Component component, ComponentAdapter adapter) Performs configuration of the tree's renderer if the adapter's column is the hierarchical column, does nothing otherwise.voidOverridden to ensure that private renderer state is kept in sync with the state of the component.voidCollapses all nodes in the treetable.voidcollapsePath(TreePath path) Collapses the node at the specified path in the treetable.voidcollapseRow(int row) Collapses the row in the treetable.voidprotected JXTreeTable.TreeTableHackerHacking around various issues.booleaneditCellAt(int row, int column, EventObject e) Overriden to invoke repaint for the particular location if the column contains the tree.voidExpands all nodes in the treetable.voidexpandPath(TreePath path) Expands the the node at the specified path in the treetable.voidexpandRow(int row) Expands the specified row in the treetable.getCellEditor(int row, int column) getCellRenderer(int row, int column) protected ComponentAdapterReturns the adapter that knows how to access the component data model.intOverridden to provide a workaround for BasicTableUI anomaly.Enumeration<?>getExpandedDescendants(TreePath parent) Returns anEnumerationof the descendants of the pathparentthat are currently expanded.booleanReturns the value of theexpandsSelectedPathsproperty.intReturns the index of the hierarchical column.getPathForLocation(int x, int y) Returns the TreePath for a given x,y location.getPathForRow(int row) Returns the TreePath for a given row.intgetRowForPath(TreePath path) Returns the row for a given TreePath.booleanReturns the value of thescrollsOnExpandproperty.booleanReturns the value of theshowsRootHandlesproperty.getStringAt(int row, int column) Returns the string representation of the cell value at the given position.intReturns the number of mouse clicks needed to expand or close a node.getToolTipText(MouseEvent event) Returns the selection model for the tree portion of the this treetable.protected JXTreeTable.TreeTableHackerReturns the underlying TreeTableModel for this JXTreeTable.protected booleanDecides whether we want to apply the hack for #168-jdnc. here: returns true if dragEnabled() and a client property with key DRAG_HACK_FLAG_KEY has a value of boolean true.booleanisCollapsed(int row) Returns true if the node at the specified display row is collapsed.booleanisCollapsed(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.booleanisExpanded(int row) Returns true if the node at the specified display row is currently expanded.booleanisExpanded(TreePath path) Returns true if the node identified by path is currently expanded.booleanisHierarchical(int column) Determines if the specified column is defined as the hierarchical column.booleanReturns true if the tree is configured for a large model.booleanReturns a boolean indicating whether the per-tree icons should be copied to the renderer on setTreeCellRenderer.booleanReturns true if the root node of the tree is displayed.booleanReturns true if the value identified by path is currently viewable, which means it is either the root or all of its parents are expanded.prepareRenderer(TableCellRenderer renderer, int row, int column) Returns the decoratedComponentused as a stamp to render the specified cell.protected voidOverridden to enable hit handle detection a mouseEvent which triggered a expand/collapse.protected voidvoidRemoves a listener forTreeExpansionevents.voidRemoves a listener forTreeSelectionevents.voidRemoves a listener forTreeWillExpandevents.voidscrollPathToVisible(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.voidsetAutoCreateRowSorter(boolean autoCreateRowSorter) voidsetClosedIcon(Icon icon) Sets the specified icon as the icon to use for rendering closed container nodes.voidsetCollapsedIcon(Icon icon) Sets the specified icon as the icon to use for rendering collapsed nodes.voidsetEnabled(boolean enabled) voidsetExpandedIcon(Icon icon) Sets the specified icon as the icon to use for rendering expanded nodes.voidsetExpandsSelectedPaths(boolean expand) Sets the value of theexpandsSelectedPathsproperty for the tree part.voidsetLargeModel(boolean newValue) Specifies whether the UI should use a large model.voidsetLeafIcon(Icon icon) Sets the specified icon as the icon to use for rendering leaf nodes.final voidsetModel(TableModel tableModel) Overrides superclass version to make sure that the specifiedTableModelis compatible with JXTreeTable before invoking the inherited version.voidsetOpenIcon(Icon icon) Sets the specified icon as the icon to use for rendering open container nodes.voidsetOverwriteRendererIcons(boolean overwrite) Property to control whether per-tree icons should be copied to the renderer on setTreeCellRenderer.voidsetRootVisible(boolean visible) Determines whether or not the root node from the TreeModel is visible.voidsetRowHeight(int rowHeight) Sets the row height for this JXTreeTable and forwards the row height to the renderering tree.final voidsetRowHeight(int row, int rowHeight) Throws UnsupportedOperationException because variable height rows are not supported.voidsetRowSorter(RowSorter<? extends TableModel> sorter) voidsetScrollsOnExpand(boolean scroll) Sets the value of thescrollsOnExpandproperty for the tree part.voidsetSelectionBackground(Color selectionBackground) voidsetSelectionForeground(Color selectionForeground) voidsetSelectionMode(int mode) Overridden to ensure that private renderer state is kept in sync with the state of the component.voidsetShowsRootHandles(boolean visible) Sets the value of theshowsRootHandlesproperty for the tree part.voidsetSortable(boolean sortable) Sets "sortable" property indicating whether or not this table supports sortable columns.voidsetToggleClickCount(int clickCount) Sets the number of mouse clicks before a node will expand or close.voidsetToolTipText(String text) voidsetTreeCellRenderer(TreeCellRenderer cellRenderer) Sets the specified TreeCellRenderer as the Tree cell renderer.voidsetTreeTableModel(TreeTableModel treeModel) Sets the data model for this JXTreeTable to the specifiedTreeTableModel.voidsizeColumnsToFit(int resizingColumn) Overriden to invoke supers implementation, and then, if the receiver is editing a Tree column, the editors bounds is reset.protected voidsuperSetAutoCreateRowSorter(boolean autoCreateRowSorter) Hook into super's setAutoCreateRowSorter for use in sub-classes which want to experiment with tree table sorting/filtering.protected voidsuperSetRowSorter(RowSorter<? extends TableModel> sorter) Hook into super's setRowSorter for use in sub-classes which want to experiment with tree table sorting/filtering.protected voidsuperSetSortable(boolean sortable) Hook into super's setSortable for use in sub-classes which want to experiment with tree table sorting/filtering.voidprotected voidUpdates Ui of renderer/editor for the hierarchical column.voidupdateUI()Methods inherited from class org.jdesktop.swingx.JXTable
addHighlighter, adjustComponentOrientation, adminSetRowHeight, columnAdded, columnPropertyChange, columnSelectionChanged, configureColumnControl, configureEnclosingScrollPane, configureSorterProperties, createDefaultColumnControl, createDefaultColumnModel, createDefaultColumnsFromModel, createDefaultEditors, createDefaultRenderers, createDefaultRowSorter, createDefaultRowSorter, createDefaultStringValueRegistry, createDefaultTableHeader, createHighlighterChangeListener, createLinkController, createRolloverProducer, doFind, doLayout, getAutoCreateColumnsFromModel, getAutoCreateRowSorter, getColumn, getColumn, getColumnControl, getColumnCount, getColumnExt, getColumnExt, getColumnExt, getColumnFactory, getColumnMargin, getColumns, getColumns, getComponentAdapter, getCompoundHighlighter, getControlsSorterProperties, getEnclosingScrollPane, getHighlighterChangeListener, getHighlighters, getLinkController, getPopupLocation, getPopupTriggerLocation, getPreferredScrollableViewportSize, getRowFilter, getScrollableTracksViewportWidth, getSearchable, getSelectionMode, getSortController, getSortedColumn, getSortedColumnIndex, getSortOrder, getSortOrder, getSortOrderCycle, getSortsOnUpdates, getStringValueRegistry, getUIString, getUIString, getVisibleColumnCount, getVisibleRowCount, hasSortController, initializeColumnPreferredWidth, initializeColumnWidths, isAutoStartEditOnKeyStroke, isCellEditable, isColumnControlVisible, isDataChanged, isEditable, isFocusCycleRoot, isHorizontalScrollEnabled, isRolloverEnabled, isSortable, isStructureChanged, isTerminateEditOnFocusLost, isUpdate, packAll, packColumn, packColumn, packSelected, packTable, postprocessModelChange, postprocessSorterChanged, prepareEditor, prepareRenderer, preprocessModelChange, removeColumnControlFromCorners, removeEditor, removeHighlighter, removeNotify, resetDefaultTableCellRendererColors, resetSortOrder, rowAtPoint, scrollCellToVisible, scrollColumnToVisible, scrollRowToVisible, setAutoResizeMode, setAutoStartEditOnKeyStroke, setColumnControl, setColumnControlVisible, setColumnFactory, setColumnMargin, setColumnModel, setColumnSequence, setComponentOrientation, setDefaultRenderer, setEditable, setFillsViewportHeight, setGridColor, setHighlighters, setHorizontalScrollEnabled, setLocale, setPreferredScrollableViewportSize, setRolloverEnabled, setRowFilter, setSearchable, setShowGrid, setShowGrid, setSortOrder, setSortOrder, setSortOrderCycle, setSortsOnUpdates, setTerminateEditOnFocusLost, setValueAt, setVisibleColumnCount, setVisibleRowCount, sorterChanged, toggleSortOrder, toggleSortOrder, transferFocus, transferFocusBackward, unconfigureColumnControl, unconfigureEnclosingScrollPane, updateColumnControlUI, updateColumnUI, updateHighlighterUI, updateHorizontalAction, updateLocaleActionState, updateLocaleState, updatePopupTrigger, updateRowHeightUIMethods inherited from class javax.swing.JTable
addColumn, addColumnSelectionInterval, addNotify, addRowSelectionInterval, changeSelection, columnAtPoint, columnMoved, columnRemoved, convertColumnIndexToModel, convertColumnIndexToView, convertRowIndexToModel, convertRowIndexToView, createDefaultDataModel, createDefaultSelectionModel, createScrollPaneForTable, editCellAt, editingCanceled, editingStopped, getAccessibleContext, getAutoResizeMode, getCellEditor, getCellRect, getCellSelectionEnabled, getColumn, getColumnClass, getColumnCount, getColumnModel, getColumnName, getColumnSelectionAllowed, getDefaultEditor, getDefaultRenderer, getDragEnabled, getDropLocation, getDropMode, getEditingColumn, getEditorComponent, getFillsViewportHeight, getGridColor, getIntercellSpacing, getModel, getPrintable, getRowCount, getRowHeight, getRowHeight, getRowMargin, getRowSelectionAllowed, getRowSorter, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableUnitIncrement, getSelectedColumn, getSelectedColumnCount, getSelectedColumns, getSelectedRow, getSelectedRowCount, getSelectedRows, getSelectionBackground, getSelectionForeground, getSelectionModel, getShowHorizontalLines, getShowVerticalLines, getSurrendersFocusOnKeystroke, getTableHeader, getUI, getUIClassID, getUpdateSelectionOnSort, getValueAt, initializeLocalVars, isCellSelected, isColumnSelected, isEditing, isRowSelected, moveColumn, paramString, print, print, print, print, print, processKeyBinding, removeColumn, removeColumnSelectionInterval, removeRowSelectionInterval, resizeAndRepaint, selectAll, setAutoCreateColumnsFromModel, setCellEditor, setCellSelectionEnabled, setColumnSelectionAllowed, setColumnSelectionInterval, setDefaultEditor, setDragEnabled, setDropMode, setEditingColumn, setEditingRow, setIntercellSpacing, setRowMargin, setRowSelectionAllowed, setRowSelectionInterval, setSelectionModel, setShowHorizontalLines, setShowVerticalLines, setSurrendersFocusOnKeystroke, setTableHeader, setUI, setUpdateSelectionOnSort, sizeColumnsToFit, valueChangedMethods inherited from class javax.swing.JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyEvent, 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, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods 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, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods 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, 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, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javax.swing.event.TableColumnModelListener
columnMoved, columnRemoved
-
Field Details
-
DRAG_HACK_FLAG_KEY
Key for clientProperty to decide whether to apply hack around #168-jdnc.- See Also:
-
DROP_HACK_FLAG_KEY
Key for clientProperty to decide whether to apply hack around #766-swingx.- See Also:
-
-
Constructor Details
-
JXTreeTable
public JXTreeTable()Constructs a JXTreeTable using aDefaultTreeTableModel. -
JXTreeTable
Constructs a JXTreeTable using the specifiedTreeTableModel.- Parameters:
treeModel- model for the JXTreeTable
-
JXTreeTable
Constructs aJXTreeTableusing the specifiedJXTreeTable.TreeTableCellRenderer.- Parameters:
renderer- cell renderer for the tree portion of this JXTreeTable instance.
-
-
Method Details
-
setSortable
public void setSortable(boolean sortable) Sets "sortable" property indicating whether or not this table supports sortable columns. Ifsortableistruethen sorting will be enabled on all columns whosesortableproperty istrue. Ifsortableisfalsethen sorting will be disabled for all columns, regardless of each column's individualsortingproperty. The default istrue.Note: as of post-1.0 this property is propagated to the SortController if controlsSorterProperties is true. Whether or not a change triggers a re-sort is up to either the concrete controller implementation (the default doesn't) or client code. This behaviour is different from old SwingX style sorting.
Overridden to do nothing. TreeTable is not sortable because there is no equivalent to RowSorter (which is targeted to linear structures) for hierarchical data.
- Overrides:
setSortablein classJXTable- Parameters:
sortable- boolean indicating whether or not this table supports sortable columns- See Also:
-
setAutoCreateRowSorter
public void setAutoCreateRowSorter(boolean autoCreateRowSorter) Overridden to
- fix core bug: replaces sorter even if flag doesn't change.
- use xflag (need because super's RowSorter creation is hard-coded.
Overridden to do nothing. TreeTable is not sortable because there is no equivalent to RowSorter (which is targeted to linear structures) for hierarchical data.
- Overrides:
setAutoCreateRowSorterin classJXTable
-
setRowSorter
Overridden propagate sort-related properties to the sorter after calling super, if the given RowSorter is of type SortController. Does nothing additional otherwise.
Overridden to do nothing. TreeTable is not sortable because there is no equivalent to RowSorter (which is targeted to linear structures) for hierarchical data.
- Overrides:
setRowSorterin classJXTable
-
superSetAutoCreateRowSorter
protected void superSetAutoCreateRowSorter(boolean autoCreateRowSorter) Hook into super's setAutoCreateRowSorter for use in sub-classes which want to experiment with tree table sorting/filtering.NOTE: While subclasses may use this method to allow access to super that usage alone will not magically turn sorting/filtering on! They have to implement an appropriate RowSorter/SortController as well. This is merely a hook to hang themselves, as requested in Issue #479-swingx
- Parameters:
autoCreateRowSorter-
-
superSetSortable
protected void superSetSortable(boolean sortable) Hook into super's setSortable for use in sub-classes which want to experiment with tree table sorting/filtering.NOTE: While subclasses may use this method to allow access to super that usage alone will not magically turn sorting/filtering on! They have to implement an appropriate RowSorter/SortController as well. This is merely a hook to hang themselves, as requested in Issue #479-swingx
- Parameters:
sortable-
-
superSetRowSorter
Hook into super's setRowSorter for use in sub-classes which want to experiment with tree table sorting/filtering.NOTE: While subclasses may use this method to allow access to super that usage alone will not magically turn sorting/filtering on! They have to implement an appropriate RowSorter/SortController as well. This is merely a hook to hang themselves, as requested in Issue #479-swingx
- Parameters:
sorter-
-
setEnabled
public void setEnabled(boolean enabled) Overridden to keep the tree's enabled in synch.
- Overrides:
setEnabledin classJComponent
-
setSelectionBackground
Overridden because super throws NPE on null param.
Overridden to keep the tree's selectionBackground in synch.
- Overrides:
setSelectionBackgroundin classJXTable
-
setSelectionForeground
Overridden because super throws NPE on null param.
Overridden to keep the tree's selectionForeground in synch.
- Overrides:
setSelectionForegroundin classJXTable
-
editCellAt
Overriden 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. You should not need to call this method directly.Additionally, there is tricksery involved to expand/collapse the nodes.
overridden to install a custom editor remover.
- Overrides:
editCellAtin classJXTable
-
processMouseEvent
Overridden to enable hit handle detection a mouseEvent which triggered a expand/collapse.- Overrides:
processMouseEventin classJComponent
-
getTreeTableHacker
-
createTreeTableHacker
Hacking around various issues. Subclass and let it return your favourite. The current default is TreeTableHackerExt5 (latest evolution to work around #1230), the old long-standing default was TreeTableHackerExt3. If you experience problems with the latest, please let us know.- Returns:
-
processMouseMotionEvent
- Overrides:
processMouseMotionEventin classJComponent
-
hackAroundDragEnabled
Decides whether we want to apply the hack for #168-jdnc. here: returns true if dragEnabled() and a client property with key DRAG_HACK_FLAG_KEY has a value of boolean true.Note: this is updated for 1.6, as the intermediate system property for enabled drag support is useless now (it's the default)
- Parameters:
me- the mouseEvent that triggered a editCellAt- Returns:
- true if the hack should be applied.
-
getEditingRow
public int getEditingRow()Overridden to provide a 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. So, overriding setBounds() 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:
getEditingRowin classJTable
-
setTreeTableModel
Sets the data model for this JXTreeTable to the specifiedTreeTableModel. The same data model may be shared by any number of JXTreeTable instances.- Parameters:
treeModel- data model for this JXTreeTable
-
getTreeTableModel
Returns the underlying TreeTableModel for this JXTreeTable.- Returns:
- the underlying TreeTableModel for this JXTreeTable
-
setModel
Overrides superclass version to make sure that the specified
TableModelis compatible with JXTreeTable before invoking the inherited version.Because JXTreeTable internally adapts an
TreeTableModelto make it a compatible TableModel, this method should never be called directly. UsesetTreeTableModelinstead.While it is possible to obtain a reference to this adapted version of the TableModel by calling
.JTable.getModel(), any attempt to call setModel() with that adapter will fail because the adapter might have been bound to a different JXTreeTable instance. If you want to extract the underlying TreeTableModel, which, by the way, can be shared, usegetTreeTableModelinstead- Overrides:
setModelin classJXTable- Parameters:
tableModel- must be a TreeTableModelAdapter- Throws:
IllegalArgumentException- if the specified tableModel is not an instance of TreeTableModelAdapter
-
tableChanged
Description copied from class:JXTableOverridden to update internal state related to enhanced functionality and hack around core bugs.
- re-calculate intialize column width and preferred scrollable size after a structureChanged if autocreateColumnsFromModel is true.
- update string representation control after structureChanged
- core bug #6791934 logic to force revalidate if appropriate
- Specified by:
tableChangedin interfaceTableModelListener- Overrides:
tableChangedin classJXTable
-
setRowHeight
public final void setRowHeight(int row, int rowHeight) Throws UnsupportedOperationException because variable height rows are not supported.- Overrides:
setRowHeightin classJTable- Parameters:
row- ignoredrowHeight- ignored- Throws:
UnsupportedOperationException- because variable height rows are not supported
-
setRowHeight
public void setRowHeight(int rowHeight) Sets the row height for this JXTreeTable and forwards the row height to the renderering tree.- Overrides:
setRowHeightin classJXTable- Parameters:
rowHeight- height of a row.- See Also:
-
adjustTreeRowHeight
protected void adjustTreeRowHeight(int tableRowHeight) Forwards tableRowHeight to tree.- Parameters:
tableRowHeight- height of a row.
-
adjustTableRowHeight
protected void adjustTableRowHeight(int treeRowHeight) Forwards treeRowHeight to table. This is for completeness only: the rendering tree is under our total control, so we don't expect any external call to tree.setRowHeight.- Parameters:
treeRowHeight- height of a row.
-
columnMarginChanged
Overridden to support enhanced auto-resize behaviour enabled and necessary.
Overridden to adjust the renderer's size.
- Specified by:
columnMarginChangedin interfaceTableColumnModelListener- Overrides:
columnMarginChangedin classJXTable- See Also:
-
setSelectionMode
public void setSelectionMode(int mode) Overridden to ensure that private renderer state is kept in sync with the state of the component. Calls the inherited version after performing the necessary synchronization. If you override this method, make sure you call this version from your version of this method.
This version maps the selection mode used by the renderer to match the selection mode specified for the table. Specifically, the modes are mapped as follows:
ListSelectionModel.SINGLE_INTERVAL_SELECTION: TreeSelectionModel.CONTIGUOUS_TREE_SELECTION; ListSelectionModel.MULTIPLE_INTERVAL_SELECTION: TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION; any other (default): TreeSelectionModel.SINGLE_TREE_SELECTION;
- Overrides:
setSelectionModein classJTable- Parameters:
mode- any of the table selection modes
-
prepareRenderer
Returns the decoratedComponentused as a stamp to render the specified cell. Overrides superclass version to provide support for cell decorators.Adjusts component orientation (guaranteed to happen before applying Highlighters).
Per-column highlighters contained in
TableColumnExt.getHighlighters()are applied to the renderer after the table highlighters.TODO kgs: interaction of search highlighter and column highlighters
Note: DefaultTableCellRenderer and subclasses require a hack to play nicely with Highlighters because it has an internal "color memory" in setForeground/setBackground. The hack is applied in
resetDefaultTableCellRendererColorswhich is called after super.prepareRenderer and before applying the Highlighters. The method is called always and for all renderers.Overridden to decorate the tree's renderer after calling super. At that point, it is only the tree itself that has been decorated.
- Overrides:
prepareRendererin classJXTable- Parameters:
renderer- theTableCellRendererto preparerow- the row of the cell to render, where 0 is the first rowcolumn- the column of the cell to render, where 0 is the first column- Returns:
- the
Componentused as a stamp to render the specified cell - See Also:
-
applyRenderer
Performs configuration of the tree's renderer if the adapter's column is the hierarchical column, does nothing otherwise.Note: this is legacy glue if the treeCellRenderer is of type DefaultTreeCellRenderer. In that case the renderer's background/foreground/Non/Selection colors are set to the tree's background/foreground depending on the adapter's selection state. Does nothing if the treeCellRenderer is backed by a ComponentProvider.
- Parameters:
component- the rendering componentadapter- component data adapter- Throws:
NullPointerException- if the specified component or adapter is null
-
setTreeCellRenderer
Sets the specified TreeCellRenderer as the Tree cell renderer.- Parameters:
cellRenderer- to use for rendering tree cells.
-
getTreeCellRenderer
-
getToolTipText
Overridden to special-case the hierarchical column.
- Overrides:
getToolTipTextin classJTable
-
setToolTipText
Overridden to set the fixed tooltip text to the tree that is rendering the hierarchical column.
- Overrides:
setToolTipTextin classJComponent
-
setCollapsedIcon
Sets the specified icon as the icon to use for rendering collapsed nodes.- Parameters:
icon- to use for rendering collapsed nodes- See Also:
-
setExpandedIcon
Sets the specified icon as the icon to use for rendering expanded nodes.- Parameters:
icon- to use for rendering expanded nodes- See Also:
-
setOpenIcon
Sets the specified icon as the icon to use for rendering open container nodes.- Parameters:
icon- to use for rendering open nodes- See Also:
-
setClosedIcon
Sets the specified icon as the icon to use for rendering closed container nodes.- Parameters:
icon- to use for rendering closed nodes- See Also:
-
setLeafIcon
Sets the specified icon as the icon to use for rendering leaf nodes.- Parameters:
icon- to use for rendering leaf nodes- See Also:
-
setOverwriteRendererIcons
public void setOverwriteRendererIcons(boolean overwrite) Property to control whether per-tree icons should be copied to the renderer on setTreeCellRenderer.The default value is false.
- Parameters:
overwrite- a boolean to indicate if the per-tree Icons should be copied to the new renderer on setTreeCellRenderer.- See Also:
-
isOverwriteRendererIcons
public boolean isOverwriteRendererIcons()Returns a boolean indicating whether the per-tree icons should be copied to the renderer on setTreeCellRenderer.- Returns:
- true if a TreeCellRenderer's icons will be overwritten with the tree's Icons, false if the renderer's icons will be unchanged.
- See Also:
-
clearSelection
public void clearSelection()Overridden to ensure that private renderer state is kept in sync with the state of the component. Calls the inherited version after performing the necessary synchronization. If you override this method, make sure you call this version from your version of this method.- Overrides:
clearSelectionin classJTable
-
collapseAll
public void collapseAll()Collapses all nodes in the treetable. -
expandAll
public void expandAll()Expands all nodes in the treetable. -
collapsePath
Collapses the node at the specified path in the treetable.- Parameters:
path- path of the node to collapse
-
expandPath
Expands the the node at the specified path in the treetable.- Parameters:
path- path of the node to expand
-
scrollPathToVisible
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. Only works when thisJTreeis contained in aJScrollPane. (doc copied from JTree) PENDING: JW - where exactly do we want to scroll? Here: the scroll is in vertical direction only. Might need to show the tree column?- Parameters:
path- theTreePathidentifying the node to bring into view
-
collapseRow
public void collapseRow(int row) Collapses the row in the treetable. If the specified row index is not valid, this method will have no effect. -
expandRow
public void expandRow(int row) Expands the specified row in the treetable. If the specified row index is not valid, this method will have no effect. -
isVisible
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. Otherwise, this method returns false.- Returns:
- true, if the value identified by path is currently viewable; false, otherwise
-
isExpanded
Returns true if the node identified by path is currently expanded. Otherwise, this method returns false.- Parameters:
path- path- Returns:
- true, if the value identified by path is currently expanded; false, otherwise
-
isExpanded
public boolean isExpanded(int row) Returns true if the node at the specified display row is currently expanded. Otherwise, this method returns false.- Parameters:
row- row- Returns:
- true, if the node at the specified display row is currently expanded. false, otherwise
-
isCollapsed
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.- Parameters:
path- path- Returns:
- true, if the value identified by path is currently collapsed; false, otherwise
-
isCollapsed
public boolean isCollapsed(int row) Returns true if the node at the specified display row is collapsed.- Parameters:
row- row- Returns:
- true, if the node at the specified display row is currently collapsed. false, otherwise
-
getExpandedDescendants
Returns anEnumerationof the descendants of the pathparentthat are currently expanded. Ifparentis not currently expanded, this will returnnull. If you expand/collapse nodes while iterating over the returnedEnumerationthis may not return all the expanded paths, or may return paths that are no longer expanded.- Parameters:
parent- the path which is to be examined- Returns:
- an
Enumerationof the descendents ofparent, ornullifparentis not currently expanded
-
getPathForLocation
Returns the TreePath for a given x,y location.- Parameters:
x- x valuey- y value- Returns:
- the
TreePathfor the givern location.
-
getPathForRow
Returns the TreePath for a given row.- Parameters:
row-- Returns:
- the
TreePathfor the given row.
-
getRowForPath
Returns the row for a given TreePath.- Parameters:
path-- Returns:
- the row for the given
TreePath.
-
setRootVisible
public void setRootVisible(boolean visible) Determines whether or not the root node from the TreeModel is visible.- Parameters:
visible- true, if the root node is visible; false, otherwise
-
isRootVisible
public boolean isRootVisible()Returns true if the root node of the tree is displayed.- Returns:
- true if the root node of the tree is displayed
-
setScrollsOnExpand
public void setScrollsOnExpand(boolean scroll) Sets the value of thescrollsOnExpandproperty for the tree part. This property specifies whether the expanded paths should be scrolled into view. In a look and feel in which a tree might not need to scroll when expanded, this property may be ignored.- Parameters:
scroll- true, if expanded paths should be scrolled into view; false, otherwise
-
getScrollsOnExpand
public boolean getScrollsOnExpand()Returns the value of thescrollsOnExpandproperty.- Returns:
- the value of the
scrollsOnExpandproperty
-
setShowsRootHandles
public void setShowsRootHandles(boolean visible) Sets the value of theshowsRootHandlesproperty for the tree part. This property specifies whether the node handles should be displayed. If handles are not supported by a particular look and feel, this property may be ignored.- Parameters:
visible- true, if root handles should be shown; false, otherwise
-
getShowsRootHandles
public boolean getShowsRootHandles()Returns the value of theshowsRootHandlesproperty.- Returns:
- the value of the
showsRootHandlesproperty
-
setExpandsSelectedPaths
public void setExpandsSelectedPaths(boolean expand) Sets the value of theexpandsSelectedPathsproperty for the tree part. This property specifies whether the selected paths should be expanded.- Parameters:
expand- true, if selected paths should be expanded; false, otherwise
-
getExpandsSelectedPaths
public boolean getExpandsSelectedPaths()Returns the value of theexpandsSelectedPathsproperty.- Returns:
- the value of the
expandsSelectedPathsproperty
-
getToggleClickCount
public int getToggleClickCount()Returns the number of mouse clicks needed to expand or close a node.- Returns:
- number of mouse clicks before node is expanded
-
setToggleClickCount
public void setToggleClickCount(int clickCount) Sets the number of mouse clicks before a node will expand or close. The default is two.- Parameters:
clickCount- the number of clicks required to expand/collapse a node.
-
isLargeModel
public boolean isLargeModel()Returns true if the tree is configured for a large model. The default value is false.- Returns:
- true if a large model is suggested
- See Also:
-
setLargeModel
public void setLargeModel(boolean newValue) Specifies whether the UI should use a large model. (Not all UIs will implement this.)NOTE: this method is exposed for completeness - currently it's not recommended to use a large model because there are some issues (not yet fully understood), namely issue #25-swingx, and probably #270-swingx.
- Parameters:
newValue- true to suggest a large model to the UI
-
addTreeExpansionListener
Adds a listener forTreeExpansionevents.- Parameters:
tel- a TreeExpansionListener that will be notified when a tree node is expanded or collapsed
-
removeTreeExpansionListener
Removes a listener forTreeExpansionevents.- Parameters:
tel- theTreeExpansionListenerto remove
-
addTreeSelectionListener
Adds a listener forTreeSelectionevents. TODO (JW): redirect event source to this.- Parameters:
tsl- a TreeSelectionListener that will be notified when a tree node is selected or deselected
-
removeTreeSelectionListener
Removes a listener forTreeSelectionevents.- Parameters:
tsl- theTreeSelectionListenerto remove
-
addTreeWillExpandListener
Adds a listener forTreeWillExpandevents. TODO (JW): redirect event source to this.- Parameters:
tel- a TreeWillExpandListener that will be notified when a tree node will be expanded or collapsed
-
removeTreeWillExpandListener
Removes a listener forTreeWillExpandevents.- Parameters:
tel- theTreeWillExpandListenerto remove
-
getTreeSelectionModel
Returns the selection model for the tree portion of the this treetable.- Returns:
- selection model for the tree portion of the this treetable
-
sizeColumnsToFit
public void sizeColumnsToFit(int resizingColumn) Overriden to invoke supers implementation, and then, if the receiver is editing a Tree column, the editors bounds is reset. The reason we have to do this is because JTable doesn't think the table is being edited, asgetEditingRowreturns -1, and therefore doesn't automaticly resize the editor for us.- Overrides:
sizeColumnsToFitin classJTable
-
isHierarchical
public boolean isHierarchical(int column) Determines if the specified column is defined as the hierarchical column.- Parameters:
column- zero-based index of the column in view coordinates- Returns:
- true if the column is the hierarchical column; false otherwise.
- Throws:
IllegalArgumentException- if the column is less than 0 or greater than or equal to the column count
-
getHierarchicalColumn
public int getHierarchicalColumn()Returns the index of the hierarchical column. This is the column that is displayed as the tree.- Returns:
- the index of the hierarchical column, -1 if there is no hierarchical column
-
getCellRenderer
Overridden to fix core bug #4614616 (NPE if
TableModel'sClassfor the column is an interface). This method guarantees to always return anot nullvalue. Returns the default renderer forObjectif super returnsnull.Note: The lookup strategy for is unchanged compared to super. Subclasses which override this with a different lookup strategy are strongly advised to implement a custom StringValueRegistry with that lookup strategy to keep the WYSIWYM in SwingX.
- Overrides:
getCellRendererin classJXTable
-
getCellEditor
- Overrides:
getCellEditorin classJTable
-
updateUI
public void updateUI()Description copied from class:JXTableAdditionally updates auto-adjusted row height and highlighters.
Another of the override motivation is to fix core issue (?? ID): super fails to update all renderers/editors.
-
updateHierarchicalRendererEditor
protected void updateHierarchicalRendererEditor()Updates Ui of renderer/editor for the hierarchical column. Need to do so manually, as not accessible by the default lookup. -
getStringAt
Returns the string representation of the cell value at the given position.Overridden to message the tree directly if the column is the view index of the hierarchical column.
PENDING JW: revisit once we switch to really using a table renderer. As is, it's a quick fix for #821-swingx: string rep for hierarchical column incorrect.
- Overrides:
getStringAtin classJXTable- Parameters:
row- the row index of the cell in view coordinatescolumn- the column index of the cell in view coordinates.- Returns:
- the string representation of the cell value as it will appear in the table.
-
getComponentAdapter
Returns the adapter that knows how to access the component data model. The component data adapter is used by filters, sorters, and highlighters.- Overrides:
getComponentAdapterin classJXTable- Returns:
- the adapter (defined in JXTable) that knows how to access the component data model
-