|
swingx Version 2005-08-19 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JTable
org.jdesktop.swingx.JXTable
org.jdesktop.swingx.JXTreeTable
public class JXTreeTable
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
!
Nested Class Summary | |
---|---|
protected static class |
JXTreeTable.TreeTableDataAdapter
|
Nested classes/interfaces inherited from class org.jdesktop.swingx.JXTable |
---|
JXTable.BooleanEditor, JXTable.BooleanRenderer, JXTable.DateRenderer, JXTable.DoubleRenderer, JXTable.GenericEditor, JXTable.IconRenderer, JXTable.NumberEditor, JXTable.NumberRenderer, 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 |
---|
dataAdapter, filters, highlighters, HORIZONTALSCROLL_ACTION_COMMAND, isXTableRowHeightSet, MATCH_HIGHLIGHTER, PACKALL_ACTION_COMMAND, PACKSELECTED_ACTION_COMMAND, searchable, UIPREFIX |
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 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. |
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. |
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. |
boolean |
getShowsRootHandles()
Returns the value of the showsRootHandles property. |
String |
getToolTipText(MouseEvent event)
|
TreeCellRenderer |
getTreeCellRenderer()
|
TreeSelectionModel |
getTreeSelectionModel()
Returns the selection model for the tree portion of the this treetable. |
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 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. |
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 |
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 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 |
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. |
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. |
void |
setSortable(boolean sortable)
overridden to do nothing. |
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 |
updateUI()
Overridden to message super and forward the method to the tree. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String DRAG_HACK_FLAG_KEY
Constructor Detail |
---|
public JXTreeTable()
DefaultTreeTableModel
.
public JXTreeTable(TreeTableModel treeModel)
TreeTableModel
.
treeModel
- model for the JXTreeTableMethod Detail |
---|
public void setSortable(boolean sortable)
setSortable
in class JXTable
sortable
- boolean indicating whether or not this table supports sortable
columnsTableColumnExt.isSortable()
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.
setShowHorizontalLines
in class JTable
show
- true, if horizontal lines should be drawn; false, if lines
should not be drawngetShowHorizontalLines
,
setRowMargin
,
setIntercellSpacing
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.
setShowVerticalLines
in class JTable
show
- true, if vertical lines should be drawn; false, if lines
should not be drawngetShowVerticalLines
,
setColumnMargin
,
setIntercellSpacing
public boolean editCellAt(int row, int column, EventObject e)
editCellAt
in class JTable
protected boolean hackAroundDragEnabled(MouseEvent me)
me
- the mouseEvent that triggered a editCellAt
public int getEditingRow()
getEditingRow
in class JTable
public void setTreeTableModel(TreeTableModel treeModel)
TreeTableModel
. The same data model
may be shared by any number of JXTreeTable instances.
treeModel
- data model for this JXTreeTablepublic TreeTableModel getTreeTableModel()
public final void setModel(TableModel tableModel)
Overrides superclass version to make sure that the specified
TableModel
is compatible with JXTreeTable before
invoking the inherited version.
Because JXTreeTable internally adapts an
TreeTableModel
to make it a compatible
TableModel, this method should never be called directly. Use
setTreeTableModel
instead.
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, use getTreeTableModel
instead
setModel
in class JXTable
tableModel
- must be a TreeTableModelAdapter
IllegalArgumentException
- if the specified tableModel is not an
instance of TreeTableModelAdapterpublic final void setRowHeight(int row, int rowHeight)
setRowHeight
in class JXTable
row
- ignoredrowHeight
- ignored
UnsupportedOperationException
- because variable height rows are
not supportedpublic void setRowHeight(int rowHeight)
setRowHeight
in class JXTable
rowHeight
- height of a rowpublic void setColumnMargin(int columnMargin)
Sets the margin between columns.
If you set the column margin to zero, make sure that you also set
showVerticalLines
to false
.
setColumnMargin
in class JXTable
columnMargin
- margin between columns; must be greater than or equal to zero.setShowVerticalLines
public void setRowMargin(int rowMargin)
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.
If you set row margin to zero, make sure that you also set
showHorizontalLines
to false
.
setRowMargin
in class JTable
rowMargin
- margin or intercell spacing between rowssetShowHorizontalLines
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;
setSelectionMode
in class JTable
mode
- any of the table selection modespublic Component prepareRenderer(TableCellRenderer renderer, int row, int column)
prepareRenderer
in class JXTable
renderer
- the TableCellRenderer
to 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
Component
used as a stamp to render the specified cellHighlighter
protected Component applyRenderer(Component component, ComponentAdapter adapter)
component
- adapter
- component data adapter
NullPointerException
- if the specified component or adapter is nullpublic void setTreeCellRenderer(TreeCellRenderer cellRenderer)
cellRenderer
- to use for rendering tree cells.public TreeCellRenderer getTreeCellRenderer()
public String getToolTipText(MouseEvent event)
getToolTipText
in class JTable
public void setCollapsedIcon(Icon icon)
icon
- to use for rendering collapsed nodespublic void setExpandedIcon(Icon icon)
icon
- to use for rendering expanded nodespublic void setOpenIcon(Icon icon)
icon
- to use for rendering open nodespublic void setClosedIcon(Icon icon)
icon
- to use for rendering closed nodespublic void setLeafIcon(Icon icon)
icon
- to use for rendering leaf nodespublic void clearSelection()
clearSelection
in class JTable
public void collapseAll()
public void expandAll()
public void collapsePath(TreePath path)
path
- path of the node to collapsepublic void expandPath(TreePath path)
path
- path of the node to expandpublic void scrollPathToVisible(TreePath path)
JTree
is contained in a JScrollPane
.
(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?
path
- the TreePath
identifying the node to
bring into viewpublic void collapseRow(int row)
public void expandRow(int row)
public void setRootVisible(boolean visible)
visible
- true, if the root node is visible; false, otherwisepublic boolean isRootVisible()
public boolean isVisible(TreePath path)
public boolean isExpanded(TreePath path)
path
- path
public boolean isExpanded(int row)
row
- row
public boolean isCollapsed(TreePath path)
path
- path
public boolean isCollapsed(int row)
row
- row
public Enumeration getExpandedDescendants(TreePath parent)
Enumeration
of the descendants of the
path parent
that
are currently expanded. If parent
is not currently
expanded, this will return null
.
If you expand/collapse nodes while
iterating over the returned Enumeration
this may not return all
the expanded paths, or may return paths that are no longer expanded.
parent
- the path which is to be examined
Enumeration
of the descendents of
parent
, or null
if
parent
is not currently expandedpublic void setExpandsSelectedPaths(boolean expand)
expandsSelectedPaths
property for the tree
part. This property specifies whether the selected paths should be expanded.
expand
- true, if selected paths should be expanded; false, otherwisepublic boolean getExpandsSelectedPaths()
expandsSelectedPaths
property.
expandsSelectedPaths
propertypublic TreePath getPathForLocation(int x, int y)
x
- x valuey
- y value
TreePath
for the givern location.public TreePath getPathForRow(int row)
row
-
TreePath
for the given row.public int getRowForPath(TreePath path)
path
-
TreePath
.public void setScrollsOnExpand(boolean scroll)
scrollsOnExpand
property 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.
scroll
- true, if expanded paths should be scrolled into view;
false, otherwisepublic boolean getScrollsOnExpand()
scrollsOnExpand
property.
scrollsOnExpand
propertypublic void setShowsRootHandles(boolean visible)
showsRootHandles
property 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.
visible
- true, if root handles should be shown; false, otherwisepublic boolean getShowsRootHandles()
showsRootHandles
property.
showsRootHandles
propertypublic void addTreeExpansionListener(TreeExpansionListener tel)
TreeExpansion
events.
TODO (JW): redirect event source to this.
tel
- a TreeExpansionListener that will be notified
when a tree node is expanded or collapsedpublic void removeTreeExpansionListener(TreeExpansionListener tel)
TreeExpansion
events.
tel
- the TreeExpansionListener
to removepublic void addTreeSelectionListener(TreeSelectionListener tsl)
TreeSelection
events.
TODO (JW): redirect event source to this.
tsl
- a TreeSelectionListener that will be notified
when a tree node is selected or deselectedpublic void removeTreeSelectionListener(TreeSelectionListener tsl)
TreeSelection
events.
tsl
- the TreeSelectionListener
to removepublic void addTreeWillExpandListener(TreeWillExpandListener tel)
TreeWillExpand
events.
TODO (JW): redirect event source to this.
tel
- a TreeWillExpandListener that will be notified
when a tree node will be expanded or collapsedpublic void removeTreeWillExpandListener(TreeWillExpandListener tel)
TreeWillExpand
events.
tel
- the TreeWillExpandListener
to removepublic TreeSelectionModel getTreeSelectionModel()
public void sizeColumnsToFit(int resizingColumn)
getEditingRow
returns
-1, and therefore doesn't automaticly resize the editor for us.
sizeColumnsToFit
in class JTable
public void updateUI()
updateUI
in class JXTable
public boolean isHierarchical(int column)
isHierarchical
in class JXTable
column
- zero-based index of the column
TreeNode
interface; false otherwise.protected ComponentAdapter getComponentAdapter()
getComponentAdapter
in class JXTable
|
swingx Version 2005-08-19 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |