Fields Summary |
---|
private static final String | uiClassID |
protected transient TreeModel | treeModelThe model that defines the tree displayed by this object. |
protected transient TreeSelectionModel | selectionModelModels the set of selected nodes in this tree. |
protected boolean | rootVisibleTrue if the root node is displayed, false if its children are
the highest visible nodes. |
protected transient TreeCellRenderer | cellRendererThe cell used to draw nodes. If null , the UI uses a default
cellRenderer . |
protected int | rowHeightHeight to use for each display row. If this is <= 0 the renderer
determines the height for each row. |
private boolean | rowHeightSet |
private transient Hashtable | expandedStateMaps from TreePath to Boolean
indicating whether or not the
particular path is expanded. This ONLY indicates whether a
given path is expanded, and NOT if it is visible or not. That
information must be determined by visiting all the parent
paths and seeing if they are visible. |
protected boolean | showsRootHandlesTrue if handles are displayed at the topmost level of the tree.
A handle is a small icon that displays adjacent to the node which
allows the user to click once to expand or collapse the node. A
common interface shows a plus sign (+) for a node which can be
expanded and a minus sign (-) for a node which can be collapsed.
Handles are always shown for nodes below the topmost level.
If the rootVisible setting specifies that the root
node is to be displayed, then that is the only node at the topmost
level. If the root node is not displayed, then all of its
children are at the topmost level of the tree. Handles are
always displayed for nodes other than the topmost.
If the root node isn't visible, it is generally a good to make
this value true. Otherwise, the tree looks exactly like a list,
and users may not know that the "list entries" are actually
tree nodes. |
private boolean | showsRootHandlesSet |
protected transient TreeSelectionRedirector | selectionRedirectorCreates a new event and passed it off the
selectionListeners . |
protected transient TreeCellEditor | cellEditorEditor for the entries. Default is null
(tree is not editable). |
protected boolean | editableIs the tree editable? Default is false. |
protected boolean | largeModelIs this tree a large model? This is a code-optimization setting.
A large model can be used when the cell height is the same for all
nodes. The UI will then cache very little information and instead
continually message the model. Without a large model the UI caches
most of the information, resulting in fewer method calls to the model.
This value is only a suggestion to the UI. Not all UIs will
take advantage of it. Default value is false. |
protected int | visibleRowCountNumber of rows to make visible at one time. This value is used for
the Scrollable interface. It determines the preferred
size of the display area. |
protected boolean | invokesStopCellEditingIf true, when editing is to be stopped by way of selection changing,
data in tree changing or other means stopCellEditing
is invoked, and changes are saved. If false,
cancelCellEditing is invoked, and changes
are discarded. Default is false. |
protected boolean | scrollsOnExpandIf true, when a node is expanded, as many of the descendants are
scrolled to be visible. |
private boolean | scrollsOnExpandSet |
protected int | toggleClickCountNumber of mouse clicks before a node is expanded. |
protected transient TreeModelListener | treeModelListenerUpdates the expandedState . |
private transient Stack | expandedStackUsed when setExpandedState is invoked,
will be a Stack of Stack s. |
private TreePath | leadPathLead selection path, may not be null . |
private TreePath | anchorPathAnchor path. |
private boolean | expandsSelectedPathsTrue if paths in the selection should be expanded. |
private boolean | settingUIThis is set to true for the life of the setUI call. |
private boolean | dragEnabledIf true, mouse presses on selections initiate a drag operation. |
private transient TreeExpansionListener | uiTreeExpansionListenerWhen addTreeExpansionListener is invoked,
and settingUI is true, this ivar gets set to the passed in
Listener . This listener is then notified first in
fireTreeCollapsed and fireTreeExpanded .
This is an ugly workaround for a way to have the UI listener
get notified before other listeners. |
private static int | TEMP_STACK_SIZEMax number of stacks to keep around. |
public static final String | CELL_RENDERER_PROPERTYBound property name for cellRenderer . |
public static final String | TREE_MODEL_PROPERTYBound property name for treeModel . |
public static final String | ROOT_VISIBLE_PROPERTYBound property name for rootVisible . |
public static final String | SHOWS_ROOT_HANDLES_PROPERTYBound property name for showsRootHandles . |
public static final String | ROW_HEIGHT_PROPERTYBound property name for rowHeight . |
public static final String | CELL_EDITOR_PROPERTYBound property name for cellEditor . |
public static final String | EDITABLE_PROPERTYBound property name for editable . |
public static final String | LARGE_MODEL_PROPERTYBound property name for largeModel . |
public static final String | SELECTION_MODEL_PROPERTYBound property name for selectionModel. |
public static final String | VISIBLE_ROW_COUNT_PROPERTYBound property name for visibleRowCount . |
public static final String | INVOKES_STOP_CELL_EDITING_PROPERTYBound property name for messagesStopCellEditing . |
public static final String | SCROLLS_ON_EXPAND_PROPERTYBound property name for scrollsOnExpand . |
public static final String | TOGGLE_CLICK_COUNT_PROPERTYBound property name for toggleClickCount . |
public static final String | LEAD_SELECTION_PATH_PROPERTYBound property name for leadSelectionPath . |
public static final String | ANCHOR_SELECTION_PATH_PROPERTYBound property name for anchor selection path. |
public static final String | EXPANDS_SELECTED_PATHS_PROPERTYBound property name for expands selected paths property |
Methods Summary |
---|
public void | addSelectionInterval(int index0, int index1)Adds the paths between index0 and index1, inclusive, to the
selection.
TreePath[] paths = getPathBetweenRows(index0, index1);
this.getSelectionModel().addSelectionPaths(paths);
|
public void | addSelectionPath(javax.swing.tree.TreePath path)Adds the node identified by the specified TreePath
to the current selection. If any component of the path isn't
viewable, and getExpandsSelectedPaths is true it is
made viewable.
Note that JTree does not allow duplicate nodes to
exist as children under the same parent -- each sibling must be
a unique object.
getSelectionModel().addSelectionPath(path);
|
public void | addSelectionPaths(javax.swing.tree.TreePath[] paths)Adds each path in the array of paths to the current selection. If
any component of any of the paths isn't viewable and
getExpandsSelectedPaths is true, it is
made viewable.
Note that JTree does not allow duplicate nodes to
exist as children under the same parent -- each sibling must be
a unique object.
getSelectionModel().addSelectionPaths(paths);
|
public void | addSelectionRow(int row)Adds the path at the specified row to the current selection.
int[] rows = { row };
addSelectionRows(rows);
|
public void | addSelectionRows(int[] rows)Adds the paths at each of the specified rows to the current selection.
TreeUI ui = getUI();
if(ui != null && rows != null) {
int numRows = rows.length;
TreePath[] paths = new TreePath[numRows];
for(int counter = 0; counter < numRows; counter++)
paths[counter] = ui.getPathForRow(this, rows[counter]);
addSelectionPaths(paths);
}
|
public void | addTreeExpansionListener(javax.swing.event.TreeExpansionListener tel)Adds a listener for TreeExpansion events.
if (settingUI) {
uiTreeExpansionListener = tel;
}
listenerList.add(TreeExpansionListener.class, tel);
|
public void | addTreeSelectionListener(javax.swing.event.TreeSelectionListener tsl)Adds a listener for TreeSelection events.
listenerList.add(TreeSelectionListener.class,tsl);
if(listenerList.getListenerCount(TreeSelectionListener.class) != 0
&& selectionRedirector == null) {
selectionRedirector = new TreeSelectionRedirector();
selectionModel.addTreeSelectionListener(selectionRedirector);
}
|
public void | addTreeWillExpandListener(javax.swing.event.TreeWillExpandListener tel)Adds a listener for TreeWillExpand events.
listenerList.add(TreeWillExpandListener.class, tel);
|
public void | cancelEditing()Cancels the current editing session. Has no effect if the
tree isn't being edited.
TreeUI tree = getUI();
if(tree != null)
tree.cancelEditing(this);
|
public void | clearSelection()Clears the selection.
getSelectionModel().clearSelection();
|
protected void | clearToggledPaths()Clears the cache of toggled tree paths. This does NOT send out
any TreeExpansionListener events.
expandedState.clear();
|
public void | collapsePath(javax.swing.tree.TreePath path)Ensures that the node identified by the specified path is
collapsed and viewable.
setExpandedState(path, false);
|
public void | collapseRow(int row)Ensures that the node in the specified row is collapsed.
If row is < 0 or >= getRowCount this
will have no effect.
collapsePath(getPathForRow(row));
|
public java.lang.String | convertValueToText(java.lang.Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus)Called by the renderers to convert the specified value to
text. This implementation returns value.toString , ignoring
all other arguments. To control the conversion, subclass this
method and use any of the arguments you need.
if(value != null) {
String sValue = value.toString();
if (sValue != null) {
return sValue;
}
}
return "";
|
protected static javax.swing.tree.TreeModel | createTreeModel(java.lang.Object value)Returns a TreeModel wrapping the specified object.
If the object is:
- an array of
Object s,
- a
Hashtable , or
- a
Vector
then a new root node is created with each of the incoming
objects as children. Otherwise, a new root is created with the
specified object as its value.
DefaultMutableTreeNode root;
if((value instanceof Object[]) || (value instanceof Hashtable) ||
(value instanceof Vector)) {
root = new DefaultMutableTreeNode("root");
DynamicUtilTreeNode.createChildren(root, value);
}
else {
root = new DynamicUtilTreeNode("root", value);
}
return new DefaultTreeModel(root, false);
|
protected javax.swing.event.TreeModelListener | createTreeModelListener()Creates and returns an instance of TreeModelHandler .
The returned
object is responsible for updating the expanded state when the
TreeModel changes.
For more information on what expanded state means, see the
JTree description above.
return new TreeModelHandler();
|
public void | expandPath(javax.swing.tree.TreePath path)Ensures that the node identified by the specified path is
expanded and viewable. If the last item in the path is a
leaf, this will have no effect.
// Only expand if not leaf!
TreeModel model = getModel();
if(path != null && model != null &&
!model.isLeaf(path.getLastPathComponent())) {
setExpandedState(path, true);
}
|
private void | expandRoot()Expands the root path, assuming the current TreeModel has been set.
TreeModel model = getModel();
if(model != null && model.getRoot() != null) {
expandPath(new TreePath(model.getRoot()));
}
|
public void | expandRow(int row)Ensures that the node in the specified row is expanded and
viewable.
If row is < 0 or >= getRowCount this
will have no effect.
expandPath(getPathForRow(row));
|
public void | fireTreeCollapsed(javax.swing.tree.TreePath path)Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the path parameter.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeExpansionEvent e = null;
if (uiTreeExpansionListener != null) {
e = new TreeExpansionEvent(this, path);
uiTreeExpansionListener.treeCollapsed(e);
}
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeExpansionListener.class &&
listeners[i + 1] != uiTreeExpansionListener) {
// Lazily create the event:
if (e == null)
e = new TreeExpansionEvent(this, path);
((TreeExpansionListener)listeners[i+1]).
treeCollapsed(e);
}
}
|
public void | fireTreeExpanded(javax.swing.tree.TreePath path)Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the path parameter.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeExpansionEvent e = null;
if (uiTreeExpansionListener != null) {
e = new TreeExpansionEvent(this, path);
uiTreeExpansionListener.treeExpanded(e);
}
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeExpansionListener.class &&
listeners[i + 1] != uiTreeExpansionListener) {
// Lazily create the event:
if (e == null)
e = new TreeExpansionEvent(this, path);
((TreeExpansionListener)listeners[i+1]).
treeExpanded(e);
}
}
|
public void | fireTreeWillCollapse(javax.swing.tree.TreePath path)Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the path parameter.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeExpansionEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeWillExpandListener.class) {
// Lazily create the event:
if (e == null)
e = new TreeExpansionEvent(this, path);
((TreeWillExpandListener)listeners[i+1]).
treeWillCollapse(e);
}
}
|
public void | fireTreeWillExpand(javax.swing.tree.TreePath path)Notifies all listeners that have registered interest for
notification on this event type. The event instance
is lazily created using the path parameter.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
TreeExpansionEvent e = null;
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==TreeWillExpandListener.class) {
// Lazily create the event:
if (e == null)
e = new TreeExpansionEvent(this, path);
((TreeWillExpandListener)listeners[i+1]).
treeWillExpand(e);
}
}
|
protected void | fireValueChanged(javax.swing.event.TreeSelectionEvent e)Notifies all listeners that have registered interest for
notification on this event type.
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
// TreeSelectionEvent e = null;
if (listeners[i]==TreeSelectionListener.class) {
// Lazily create the event:
// if (e == null)
// e = new ListSelectionEvent(this, firstIndex, lastIndex);
((TreeSelectionListener)listeners[i+1]).valueChanged(e);
}
}
|
public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this JTree.
For JTrees, the AccessibleContext takes the form of an
AccessibleJTree.
A new AccessibleJTree instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleJTree();
}
return accessibleContext;
|
public javax.swing.tree.TreePath | getAnchorSelectionPath()Returns the path identified as the anchor.
return anchorPath;
|
private java.lang.Object | getArchivableExpandedState()Returns an object that can be archived indicating what nodes are
expanded and what aren't. The objects from the model are NOT
written out.
TreeModel model = getModel();
if(model != null) {
Enumeration paths = expandedState.keys();
if(paths != null) {
Vector state = new Vector();
while(paths.hasMoreElements()) {
TreePath path = (TreePath)paths.nextElement();
Object archivePath;
try {
archivePath = getModelIndexsForPath(path);
} catch (Error error) {
archivePath = null;
}
if(archivePath != null) {
state.addElement(archivePath);
state.addElement(expandedState.get(path));
}
}
return state;
}
}
return null;
|
public javax.swing.tree.TreeCellEditor | getCellEditor()Returns the editor used to edit entries in the tree.
return cellEditor;
|
public javax.swing.tree.TreeCellRenderer | getCellRenderer()Returns the current TreeCellRenderer
that is rendering each cell.
return cellRenderer;
|
public javax.swing.tree.TreePath | getClosestPathForLocation(int x, int y)Returns the path to the node that is closest to x,y. If
no nodes are currently viewable, or there is no model, returns
null , otherwise it always returns a valid path. To test if
the node is exactly at x, y, get the node's bounds and
test x, y against that.
TreeUI tree = getUI();
if(tree != null)
return tree.getClosestPathForLocation(this, x, y);
return null;
|
public int | getClosestRowForLocation(int x, int y)Returns the row to the node that is closest to x,y. If no nodes
are viewable or there is no model, returns -1. Otherwise,
it always returns a valid row. To test if the returned object is
exactly at x, y, get the bounds for the node at the returned
row and test x, y against that.
return getRowForPath(getClosestPathForLocation(x, y));
|
protected static javax.swing.tree.TreeModel | getDefaultTreeModel()Creates and returns a sample TreeModel .
Used primarily for beanbuilders to show something interesting.
DefaultMutableTreeNode root = new DefaultMutableTreeNode("JTree");
DefaultMutableTreeNode parent;
parent = new DefaultMutableTreeNode("colors");
root.add(parent);
parent.add(new DefaultMutableTreeNode("blue"));
parent.add(new DefaultMutableTreeNode("violet"));
parent.add(new DefaultMutableTreeNode("red"));
parent.add(new DefaultMutableTreeNode("yellow"));
parent = new DefaultMutableTreeNode("sports");
root.add(parent);
parent.add(new DefaultMutableTreeNode("basketball"));
parent.add(new DefaultMutableTreeNode("soccer"));
parent.add(new DefaultMutableTreeNode("football"));
parent.add(new DefaultMutableTreeNode("hockey"));
parent = new DefaultMutableTreeNode("food");
root.add(parent);
parent.add(new DefaultMutableTreeNode("hot dogs"));
parent.add(new DefaultMutableTreeNode("pizza"));
parent.add(new DefaultMutableTreeNode("ravioli"));
parent.add(new DefaultMutableTreeNode("bananas"));
return new DefaultTreeModel(root);
|
private javax.swing.tree.TreePath[] | getDescendantSelectedPaths(javax.swing.tree.TreePath path, boolean includePath)Returns an array of paths in the selection that are descendants of
path . The returned array may contain null s.
TreeSelectionModel sm = getSelectionModel();
TreePath[] selPaths = (sm != null) ? sm.getSelectionPaths() :
null;
if(selPaths != null) {
boolean shouldRemove = false;
for(int counter = selPaths.length - 1; counter >= 0; counter--) {
if(selPaths[counter] != null &&
path.isDescendant(selPaths[counter]) &&
(!path.equals(selPaths[counter]) || includePath))
shouldRemove = true;
else
selPaths[counter] = null;
}
if(!shouldRemove) {
selPaths = null;
}
return selPaths;
}
return null;
|
protected java.util.Enumeration | getDescendantToggledPaths(javax.swing.tree.TreePath parent)Returns an Enumeration of TreePaths
that have been expanded that
are descendants of parent .
if(parent == null)
return null;
Vector descendants = new Vector();
Enumeration nodes = expandedState.keys();
TreePath path;
while(nodes.hasMoreElements()) {
path = (TreePath)nodes.nextElement();
if(parent.isDescendant(path))
descendants.addElement(path);
}
return descendants.elements();
|
public boolean | getDragEnabled()Gets the value of the dragEnabled property.
return dragEnabled;
|
public javax.swing.tree.TreePath | getEditingPath()Returns the path to the element that is currently being edited.
TreeUI tree = getUI();
if(tree != null)
return tree.getEditingPath(this);
return null;
|
public java.util.Enumeration | getExpandedDescendants(javax.swing.tree.TreePath parent)Returns an 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.
if(!isExpanded(parent))
return null;
Enumeration toggledPaths = expandedState.keys();
Vector elements = null;
TreePath path;
Object value;
if(toggledPaths != null) {
while(toggledPaths.hasMoreElements()) {
path = (TreePath)toggledPaths.nextElement();
value = expandedState.get(path);
// Add the path if it is expanded, a descendant of parent,
// and it is visible (all parents expanded). This is rather
// expensive!
if(path != parent && value != null &&
((Boolean)value).booleanValue() &&
parent.isDescendant(path) && isVisible(path)) {
if (elements == null) {
elements = new Vector();
}
elements.addElement(path);
}
}
}
if (elements == null) {
Set<TreePath> empty = Collections.emptySet();
return Collections.enumeration(empty);
}
return elements.elements();
|
public boolean | getExpandsSelectedPaths()Returns the expandsSelectedPaths property.
return expandsSelectedPaths;
|
public boolean | getInvokesStopCellEditing()Returns the indicator that tells what happens when editing is
interrupted.
return invokesStopCellEditing;
|
public java.lang.Object | getLastSelectedPathComponent()Returns the last path component in the first node of the current
selection.
TreePath selPath = getSelectionModel().getSelectionPath();
if(selPath != null)
return selPath.getLastPathComponent();
return null;
|
public javax.swing.tree.TreePath | getLeadSelectionPath()Returns the path identified as the lead.
return leadPath;
|
public int | getLeadSelectionRow()Returns the row index corresponding to the lead path.
TreePath leadPath = getLeadSelectionPath();
if (leadPath != null) {
return getRowForPath(leadPath);
}
return -1;
|
public int | getMaxSelectionRow()Returns the last selected row.
return getSelectionModel().getMaxSelectionRow();
|
public int | getMinSelectionRow()Gets the first selected row.
return getSelectionModel().getMinSelectionRow();
|
public javax.swing.tree.TreeModel | getModel()Returns the TreeModel that is providing the data.
return treeModel;
|
private int[] | getModelIndexsForPath(javax.swing.tree.TreePath path)Returns an array of integers specifying the indexs of the
components in the path . If path is
the root, this will return an empty array. If path
is null , null will be returned.
if(path != null) {
TreeModel model = getModel();
int count = path.getPathCount();
int[] indexs = new int[count - 1];
Object parent = model.getRoot();
for(int counter = 1; counter < count; counter++) {
indexs[counter - 1] = model.getIndexOfChild
(parent, path.getPathComponent(counter));
parent = path.getPathComponent(counter);
if(indexs[counter - 1] < 0)
return null;
}
return indexs;
}
return null;
|
public javax.swing.tree.TreePath | getNextMatch(java.lang.String prefix, int startingRow, javax.swing.text.Position$Bias bias)Returns the TreePath to the next tree element that
begins with a prefix. To handle the conversion of a
TreePath into a String, convertValueToText
is used.
int max = getRowCount();
if (prefix == null) {
throw new IllegalArgumentException();
}
if (startingRow < 0 || startingRow >= max) {
throw new IllegalArgumentException();
}
prefix = prefix.toUpperCase();
// start search from the next/previous element froom the
// selected element
int increment = (bias == Position.Bias.Forward) ? 1 : -1;
int row = startingRow;
do {
TreePath path = getPathForRow(row);
String text = convertValueToText(
path.getLastPathComponent(), isRowSelected(row),
isExpanded(row), true, row, false);
if (text.toUpperCase().startsWith(prefix)) {
return path;
}
row = (row + increment + max) % max;
} while (row != startingRow);
return null;
|
protected javax.swing.tree.TreePath[] | getPathBetweenRows(int index0, int index1)Returns JTreePath instances representing the path
between index0 and index1 (including index1).
Returns null if there is no tree.
int newMinIndex, newMaxIndex;
TreeUI tree = getUI();
newMinIndex = Math.min(index0, index1);
newMaxIndex = Math.max(index0, index1);
if(tree != null) {
TreePath[] selection = new TreePath[newMaxIndex -
newMinIndex + 1];
for(int counter = newMinIndex; counter <= newMaxIndex; counter++)
selection[counter - newMinIndex] = tree.getPathForRow(this,
counter);
return selection;
}
return null;
|
public java.awt.Rectangle | getPathBounds(javax.swing.tree.TreePath path)Returns the Rectangle that the specified node will be drawn
into. Returns null if any component in the path is hidden
(under a collapsed parent).
Note:
This method returns a valid rectangle, even if the specified
node is not currently displayed.
TreeUI tree = getUI();
if(tree != null)
return tree.getPathBounds(this, path);
return null;
|
private javax.swing.tree.TreePath | getPathForIndexs(int[] indexs)Returns a TreePath created by obtaining the children
for each of the indices in indexs . If indexs
or the TreeModel is null , it will return
null .
if(indexs == null)
return null;
TreeModel model = getModel();
if(model == null)
return null;
int count = indexs.length;
Object parent = model.getRoot();
TreePath parentPath = new TreePath(parent);
for(int counter = 0; counter < count; counter++) {
parent = model.getChild(parent, indexs[counter]);
if(parent == null)
return null;
parentPath = parentPath.pathByAddingChild(parent);
}
return parentPath;
|
public javax.swing.tree.TreePath | getPathForLocation(int x, int y)Returns the path for the node at the specified location.
TreePath closestPath = getClosestPathForLocation(x, y);
if(closestPath != null) {
Rectangle pathBounds = getPathBounds(closestPath);
if(pathBounds != null &&
x >= pathBounds.x && x < (pathBounds.x + pathBounds.width) &&
y >= pathBounds.y && y < (pathBounds.y + pathBounds.height))
return closestPath;
}
return null;
|
public javax.swing.tree.TreePath | getPathForRow(int row)Returns the path for the specified row. If row is
not visible, null is returned.
TreeUI tree = getUI();
if(tree != null)
return tree.getPathForRow(this, row);
return null;
|
public java.awt.Dimension | getPreferredScrollableViewportSize()Returns the preferred display size of a JTree . The height is
determined from getVisibleRowCount and the width
is the current preferred width.
int width = getPreferredSize().width;
int visRows = getVisibleRowCount();
int height = -1;
if(isFixedRowHeight())
height = visRows * getRowHeight();
else {
TreeUI ui = getUI();
if (ui != null && visRows > 0) {
int rc = ui.getRowCount(this);
if (rc >= visRows) {
Rectangle bounds = getRowBounds(visRows - 1);
if (bounds != null) {
height = bounds.y + bounds.height;
}
}
else if (rc > 0) {
Rectangle bounds = getRowBounds(0);
if (bounds != null) {
height = bounds.height * visRows;
}
}
}
if (height == -1) {
height = 16 * visRows;
}
}
return new Dimension(width, height);
|
public java.awt.Rectangle | getRowBounds(int row)Returns the Rectangle that the node at the specified row is
drawn in.
return getPathBounds(getPathForRow(row));
|
public int | getRowCount()Returns the number of rows that are currently being displayed.
TreeUI tree = getUI();
if(tree != null)
return tree.getRowCount(this);
return 0;
|
public int | getRowForLocation(int x, int y)Returns the row for the specified location.
return getRowForPath(getPathForLocation(x, y));
|
public int | getRowForPath(javax.swing.tree.TreePath path)Returns the row that displays the node identified by the specified
path.
TreeUI tree = getUI();
if(tree != null)
return tree.getRowForPath(this, path);
return -1;
|
public int | getRowHeight()Returns the height of each row. If the returned value is less than
or equal to 0 the height for each row is determined by the
renderer.
return rowHeight;
|
public int | getScrollableBlockIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)Returns the amount for a block increment, which is the height or
width of visibleRect , based on orientation .
return (orientation == SwingConstants.VERTICAL) ? visibleRect.height :
visibleRect.width;
|
public boolean | getScrollableTracksViewportHeight()Returns false to indicate that the height of the viewport does not
determine the height of the table, unless the preferred height
of the tree is smaller than the viewports height. In other words:
ensure that the tree is never smaller than its viewport.
if (getParent() instanceof JViewport) {
return (((JViewport)getParent()).getHeight() > getPreferredSize().height);
}
return false;
|
public boolean | getScrollableTracksViewportWidth()Returns false to indicate that the width of the viewport does not
determine the width of the table, unless the preferred width of
the tree is smaller than the viewports width. In other words:
ensure that the tree is never smaller than its viewport.
if (getParent() instanceof JViewport) {
return (((JViewport)getParent()).getWidth() > getPreferredSize().width);
}
return false;
|
public int | getScrollableUnitIncrement(java.awt.Rectangle visibleRect, int orientation, int direction)Returns the amount to increment when scrolling. The amount is
the height of the first displayed row that isn't completely in view
or, if it is totally displayed, the height of the next row in the
scrolling direction.
if(orientation == SwingConstants.VERTICAL) {
Rectangle rowBounds;
int firstIndex = getClosestRowForLocation
(0, visibleRect.y);
if(firstIndex != -1) {
rowBounds = getRowBounds(firstIndex);
if(rowBounds.y != visibleRect.y) {
if(direction < 0) {
// UP
return Math.max(0, (visibleRect.y - rowBounds.y));
}
return (rowBounds.y + rowBounds.height - visibleRect.y);
}
if(direction < 0) { // UP
if(firstIndex != 0) {
rowBounds = getRowBounds(firstIndex - 1);
return rowBounds.height;
}
}
else {
return rowBounds.height;
}
}
return 0;
}
return 4;
|
public boolean | getScrollsOnExpand()Returns the value of the scrollsOnExpand property.
return scrollsOnExpand;
|
public int | getSelectionCount()Returns the number of nodes selected.
return selectionModel.getSelectionCount();
|
public javax.swing.tree.TreeSelectionModel | getSelectionModel()Returns the model for selections. This should always return a
non-null value. If you don't want to allow anything
to be selected
set the selection model to null , which forces an empty
selection model to be used.
return selectionModel;
|
public javax.swing.tree.TreePath | getSelectionPath()Returns the path to the first selected node.
return getSelectionModel().getSelectionPath();
|
public javax.swing.tree.TreePath[] | getSelectionPaths()Returns the paths of all selected values.
return getSelectionModel().getSelectionPaths();
|
public int[] | getSelectionRows()Returns all of the currently selected rows. This method is simply
forwarded to the TreeSelectionModel .
If nothing is selected null or an empty array will
be returned, based on the TreeSelectionModel
implementation.
return getSelectionModel().getSelectionRows();
|
public boolean | getShowsRootHandles()Returns the value of the showsRootHandles property.
return showsRootHandles;
|
public int | getToggleClickCount()Returns the number of mouse clicks needed to expand or close a node.
return toggleClickCount;
|
public java.lang.String | getToolTipText(java.awt.event.MouseEvent event)Overrides JComponent 's getToolTipText
method in order to allow
renderer's tips to be used if it has text set.
NOTE: For JTree to properly display tooltips of its
renderers, JTree must be a registered component with the
ToolTipManager . This can be done by invoking
ToolTipManager.sharedInstance().registerComponent(tree) .
This is not done automatically!
if(event != null) {
Point p = event.getPoint();
int selRow = getRowForLocation(p.x, p.y);
TreeCellRenderer r = getCellRenderer();
if(selRow != -1 && r != null) {
TreePath path = getPathForRow(selRow);
Object lastPath = path.getLastPathComponent();
Component rComponent = r.getTreeCellRendererComponent
(this, lastPath, isRowSelected(selRow),
isExpanded(selRow), getModel().isLeaf(lastPath), selRow,
true);
if(rComponent instanceof JComponent) {
MouseEvent newEvent;
Rectangle pathBounds = getPathBounds(path);
p.translate(-pathBounds.x, -pathBounds.y);
newEvent = new MouseEvent(rComponent, event.getID(),
event.getWhen(),
event.getModifiers(),
p.x, p.y, event.getClickCount(),
event.isPopupTrigger());
return ((JComponent)rComponent).getToolTipText(newEvent);
}
}
}
return null;
|
public javax.swing.event.TreeExpansionListener[] | getTreeExpansionListeners()Returns an array of all the TreeExpansionListener s added
to this JTree with addTreeExpansionListener().
return (TreeExpansionListener[])listenerList.getListeners(
TreeExpansionListener.class);
|
public javax.swing.event.TreeSelectionListener[] | getTreeSelectionListeners()Returns an array of all the TreeSelectionListener s added
to this JTree with addTreeSelectionListener().
return (TreeSelectionListener[])listenerList.getListeners(
TreeSelectionListener.class);
|
public javax.swing.event.TreeWillExpandListener[] | getTreeWillExpandListeners()Returns an array of all the TreeWillExpandListener s added
to this JTree with addTreeWillExpandListener().
return (TreeWillExpandListener[])listenerList.getListeners(
TreeWillExpandListener.class);
|
public javax.swing.plaf.TreeUI | getUI()Returns the L&F object that renders this component.
return (TreeUI)ui;
|
public java.lang.String | getUIClassID()Returns the name of the L&F class that renders this component.
return uiClassID;
|
public int | getVisibleRowCount()Returns the number of rows that are displayed in the display area.
return visibleRowCount;
|
public boolean | hasBeenExpanded(javax.swing.tree.TreePath path)Returns true if the node identified by the path has ever been
expanded.
return (path != null && expandedState.get(path) != null);
|
public boolean | isCollapsed(javax.swing.tree.TreePath path)Returns true if the value identified by path is currently collapsed,
this will return false if any of the values in path are currently
not being displayed.
return !isExpanded(path);
|
public boolean | isCollapsed(int row)Returns true if the node at the specified display row is collapsed.
return !isExpanded(row);
|
public boolean | isEditable()Returns true if the tree is editable.
return editable;
|
public boolean | isEditing()Returns true if the tree is being edited. The item that is being
edited can be obtained using getSelectionPath .
TreeUI tree = getUI();
if(tree != null)
return tree.isEditing(this);
return false;
|
public boolean | isExpanded(javax.swing.tree.TreePath path)Returns true if the node identified by the path is currently expanded,
if(path == null)
return false;
// Is this node expanded?
Object value = expandedState.get(path);
if(value == null || !((Boolean)value).booleanValue())
return false;
// It is, make sure its parent is also expanded.
TreePath parentPath = path.getParentPath();
if(parentPath != null)
return isExpanded(parentPath);
return true;
|
public boolean | isExpanded(int row)Returns true if the node at the specified display row is currently
expanded.
TreeUI tree = getUI();
if(tree != null) {
TreePath path = tree.getPathForRow(this, row);
if(path != null) {
Boolean value = (Boolean)expandedState.get(path);
return (value != null && value.booleanValue());
}
}
return false;
|
public boolean | isFixedRowHeight()Returns true if the height of each display row is a fixed size.
return (rowHeight > 0);
|
public boolean | isLargeModel()Returns true if the tree is configured for a large model.
return largeModel;
|
public boolean | isPathEditable(javax.swing.tree.TreePath path)Returns isEditable . This is invoked from the UI before
editing begins to insure that the given path can be edited. This
is provided as an entry point for subclassers to add filtered
editing without having to resort to creating a new editor.
return isEditable();
|
public boolean | isPathSelected(javax.swing.tree.TreePath path)Returns true if the item identified by the path is currently selected.
return getSelectionModel().isPathSelected(path);
|
public boolean | isRootVisible()Returns true if the root node of the tree is displayed.
return rootVisible;
|
public boolean | isRowSelected(int row)Returns true if the node identified by row is selected.
return getSelectionModel().isRowSelected(row);
|
public boolean | isSelectionEmpty()Returns true if the selection is currently empty.
return getSelectionModel().isSelectionEmpty();
|
public boolean | isVisible(javax.swing.tree.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.
Otherwise, this method returns false.
if(path != null) {
TreePath parentPath = path.getParentPath();
if(parentPath != null)
return isExpanded(parentPath);
// Root.
return true;
}
return false;
|
public void | makeVisible(javax.swing.tree.TreePath path)Ensures that the node identified by path is currently viewable.
if(path != null) {
TreePath parentPath = path.getParentPath();
if(parentPath != null) {
expandPath(parentPath);
}
}
|
protected java.lang.String | paramString()Returns a string representation of this JTree .
This method
is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not
be null .
String rootVisibleString = (rootVisible ?
"true" : "false");
String showsRootHandlesString = (showsRootHandles ?
"true" : "false");
String editableString = (editable ?
"true" : "false");
String largeModelString = (largeModel ?
"true" : "false");
String invokesStopCellEditingString = (invokesStopCellEditing ?
"true" : "false");
String scrollsOnExpandString = (scrollsOnExpand ?
"true" : "false");
return super.paramString() +
",editable=" + editableString +
",invokesStopCellEditing=" + invokesStopCellEditingString +
",largeModel=" + largeModelString +
",rootVisible=" + rootVisibleString +
",rowHeight=" + rowHeight +
",scrollsOnExpand=" + scrollsOnExpandString +
",showsRootHandles=" + showsRootHandlesString +
",toggleClickCount=" + toggleClickCount +
",visibleRowCount=" + visibleRowCount;
|
private void | readObject(java.io.ObjectInputStream s)
s.defaultReadObject();
// Create an instance of expanded state.
expandedState = new Hashtable();
expandedStack = new Stack();
Vector values = (Vector)s.readObject();
int indexCounter = 0;
int maxCounter = values.size();
if(indexCounter < maxCounter && values.elementAt(indexCounter).
equals("cellRenderer")) {
cellRenderer = (TreeCellRenderer)values.elementAt(++indexCounter);
indexCounter++;
}
if(indexCounter < maxCounter && values.elementAt(indexCounter).
equals("cellEditor")) {
cellEditor = (TreeCellEditor)values.elementAt(++indexCounter);
indexCounter++;
}
if(indexCounter < maxCounter && values.elementAt(indexCounter).
equals("treeModel")) {
treeModel = (TreeModel)values.elementAt(++indexCounter);
indexCounter++;
}
if(indexCounter < maxCounter && values.elementAt(indexCounter).
equals("selectionModel")) {
selectionModel = (TreeSelectionModel)values.elementAt(++indexCounter);
indexCounter++;
}
if(indexCounter < maxCounter && values.elementAt(indexCounter).
equals("expandedState")) {
unarchiveExpandedState(values.elementAt(++indexCounter));
indexCounter++;
}
// Reinstall the redirector.
if(listenerList.getListenerCount(TreeSelectionListener.class) != 0) {
selectionRedirector = new TreeSelectionRedirector();
selectionModel.addTreeSelectionListener(selectionRedirector);
}
// Listener to TreeModel.
if(treeModel != null) {
treeModelListener = createTreeModelListener();
if(treeModelListener != null)
treeModel.addTreeModelListener(treeModelListener);
}
|
protected boolean | removeDescendantSelectedPaths(javax.swing.tree.TreePath path, boolean includePath)Removes any paths in the selection that are descendants of
path . If includePath is true and
path is selected, it will be removed from the selection.
TreePath[] toRemove = getDescendantSelectedPaths(path, includePath);
if (toRemove != null) {
getSelectionModel().removeSelectionPaths(toRemove);
return true;
}
return false;
|
void | removeDescendantSelectedPaths(javax.swing.event.TreeModelEvent e)Removes any paths from the selection model that are descendants of
the nodes identified by in e .
TreePath pPath = e.getTreePath();
Object[] oldChildren = e.getChildren();
TreeSelectionModel sm = getSelectionModel();
if (sm != null && pPath != null && oldChildren != null &&
oldChildren.length > 0) {
for (int counter = oldChildren.length - 1; counter >= 0;
counter--) {
// Might be better to call getDescendantSelectedPaths
// numerous times, then push to the model.
removeDescendantSelectedPaths(pPath.pathByAddingChild
(oldChildren[counter]), true);
}
}
|
protected void | removeDescendantToggledPaths(java.util.Enumeration toRemove)Removes any descendants of the TreePaths in
toRemove
that have been expanded.
if(toRemove != null) {
while(toRemove.hasMoreElements()) {
Enumeration descendants = getDescendantToggledPaths
((TreePath)toRemove.nextElement());
if(descendants != null) {
while(descendants.hasMoreElements()) {
expandedState.remove(descendants.nextElement());
}
}
}
}
|
public void | removeSelectionInterval(int index0, int index1)Removes the nodes between index0 and index1, inclusive, from the
selection.
TreePath[] paths = getPathBetweenRows(index0, index1);
this.getSelectionModel().removeSelectionPaths(paths);
|
public void | removeSelectionPath(javax.swing.tree.TreePath path)Removes the node identified by the specified path from the current
selection.
this.getSelectionModel().removeSelectionPath(path);
|
public void | removeSelectionPaths(javax.swing.tree.TreePath[] paths)Removes the nodes identified by the specified paths from the
current selection.
this.getSelectionModel().removeSelectionPaths(paths);
|
public void | removeSelectionRow(int row)Removes the row at the index row from the current
selection.
int[] rows = { row };
removeSelectionRows(rows);
|
public void | removeSelectionRows(int[] rows)Removes the rows that are selected at each of the specified
rows.
TreeUI ui = getUI();
if(ui != null && rows != null) {
int numRows = rows.length;
TreePath[] paths = new TreePath[numRows];
for(int counter = 0; counter < numRows; counter++)
paths[counter] = ui.getPathForRow(this, rows[counter]);
removeSelectionPaths(paths);
}
|
public void | removeTreeExpansionListener(javax.swing.event.TreeExpansionListener tel)Removes a listener for TreeExpansion events.
listenerList.remove(TreeExpansionListener.class, tel);
if (uiTreeExpansionListener == tel) {
uiTreeExpansionListener = null;
}
|
public void | removeTreeSelectionListener(javax.swing.event.TreeSelectionListener tsl)Removes a TreeSelection listener.
listenerList.remove(TreeSelectionListener.class,tsl);
if(listenerList.getListenerCount(TreeSelectionListener.class) == 0
&& selectionRedirector != null) {
selectionModel.removeTreeSelectionListener
(selectionRedirector);
selectionRedirector = null;
}
|
public void | removeTreeWillExpandListener(javax.swing.event.TreeWillExpandListener tel)Removes a listener for TreeWillExpand events.
listenerList.remove(TreeWillExpandListener.class, tel);
|
public void | scrollPathToVisible(javax.swing.tree.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. Only works when this
JTree is contained in a JScrollPane .
if(path != null) {
makeVisible(path);
Rectangle bounds = getPathBounds(path);
if(bounds != null) {
scrollRectToVisible(bounds);
if (accessibleContext != null) {
((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
}
}
}
|
public void | scrollRowToVisible(int row)Scrolls the item identified by row until it is displayed. The minimum
of amount of scrolling necessary to bring the row into view
is performed. Only works when this JTree is contained in a
JScrollPane .
scrollPathToVisible(getPathForRow(row));
|
public void | setAnchorSelectionPath(javax.swing.tree.TreePath newPath)Sets the path identified as the anchor.
The anchor is not maintained by JTree , rather the UI will
update it.
TreePath oldValue = anchorPath;
anchorPath = newPath;
firePropertyChange(ANCHOR_SELECTION_PATH_PROPERTY, oldValue, newPath);
|
public void | setCellEditor(javax.swing.tree.TreeCellEditor cellEditor)Sets the cell editor. A null value implies that the
tree cannot be edited. If this represents a change in the
cellEditor , the propertyChange
method is invoked on all listeners.
TreeCellEditor oldEditor = this.cellEditor;
this.cellEditor = cellEditor;
firePropertyChange(CELL_EDITOR_PROPERTY, oldEditor, cellEditor);
invalidate();
|
public void | setCellRenderer(javax.swing.tree.TreeCellRenderer x)Sets the TreeCellRenderer that will be used to
draw each cell.
TreeCellRenderer oldValue = cellRenderer;
cellRenderer = x;
firePropertyChange(CELL_RENDERER_PROPERTY, oldValue, cellRenderer);
invalidate();
|
public void | setDragEnabled(boolean b)Sets the dragEnabled property,
which must be true to enable
automatic drag handling (the first part of drag and drop)
on this component.
The transferHandler property needs to be set
to a non-null value for the drag to do
anything. The default value of the dragEnabled
property
is false .
When automatic drag handling is enabled,
most look and feels begin a drag-and-drop operation
whenever the user presses the mouse button over a selection
and then moves the mouse a few pixels.
Setting this property to true
can therefore have a subtle effect on
how selections behave.
Some look and feels might not support automatic drag and drop;
they will ignore this property. You can work around such
look and feels by modifying the component
to directly call the exportAsDrag method of a
TransferHandler .
if (b && GraphicsEnvironment.isHeadless()) {
throw new HeadlessException();
}
dragEnabled = b;
|
public void | setEditable(boolean flag)Determines whether the tree is editable. Fires a property
change event if the new setting is different from the existing
setting.
boolean oldValue = this.editable;
this.editable = flag;
firePropertyChange(EDITABLE_PROPERTY, oldValue, flag);
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
(oldValue ? AccessibleState.EDITABLE : null),
(flag ? AccessibleState.EDITABLE : null));
}
|
protected void | setExpandedState(javax.swing.tree.TreePath path, boolean state)Sets the expanded state of this JTree .
If state is
true, all parents of path and path are marked as
expanded. If state is false, all parents of
path are marked EXPANDED, but path itself
is marked collapsed.
This will fail if a TreeWillExpandListener vetos it.
if(path != null) {
// Make sure all parents of path are expanded.
Stack stack;
TreePath parentPath = path.getParentPath();
if (expandedStack.size() == 0) {
stack = new Stack();
}
else {
stack = (Stack)expandedStack.pop();
}
try {
while(parentPath != null) {
if(isExpanded(parentPath)) {
parentPath = null;
}
else {
stack.push(parentPath);
parentPath = parentPath.getParentPath();
}
}
for(int counter = stack.size() - 1; counter >= 0; counter--) {
parentPath = (TreePath)stack.pop();
if(!isExpanded(parentPath)) {
try {
fireTreeWillExpand(parentPath);
} catch (ExpandVetoException eve) {
// Expand vetoed!
return;
}
expandedState.put(parentPath, Boolean.TRUE);
fireTreeExpanded(parentPath);
if (accessibleContext != null) {
((AccessibleJTree)accessibleContext).
fireVisibleDataPropertyChange();
}
}
}
}
finally {
if (expandedStack.size() < TEMP_STACK_SIZE) {
stack.removeAllElements();
expandedStack.push(stack);
}
}
if(!state) {
// collapse last path.
Object cValue = expandedState.get(path);
if(cValue != null && ((Boolean)cValue).booleanValue()) {
try {
fireTreeWillCollapse(path);
}
catch (ExpandVetoException eve) {
return;
}
expandedState.put(path, Boolean.FALSE);
fireTreeCollapsed(path);
if (removeDescendantSelectedPaths(path, false) &&
!isPathSelected(path)) {
// A descendant was selected, select the parent.
addSelectionPath(path);
}
if (accessibleContext != null) {
((AccessibleJTree)accessibleContext).
fireVisibleDataPropertyChange();
}
}
}
else {
// Expand last path.
Object cValue = expandedState.get(path);
if(cValue == null || !((Boolean)cValue).booleanValue()) {
try {
fireTreeWillExpand(path);
}
catch (ExpandVetoException eve) {
return;
}
expandedState.put(path, Boolean.TRUE);
fireTreeExpanded(path);
if (accessibleContext != null) {
((AccessibleJTree)accessibleContext).
fireVisibleDataPropertyChange();
}
}
}
}
|
public void | setExpandsSelectedPaths(boolean newValue)Configures the expandsSelectedPaths property. If
true, any time the selection is changed, either via the
TreeSelectionModel , or the cover methods provided by
JTree , the TreePath s parents will be
expanded to make them visible (visible meaning the parent path is
expanded, not necessarily in the visible rectangle of the
JTree ). If false, when the selection
changes the nodes parent is not made visible (all its parents expanded).
This is useful if you wish to have your selection model maintain paths
that are not always visible (all parents expanded).
boolean oldValue = expandsSelectedPaths;
expandsSelectedPaths = newValue;
firePropertyChange(EXPANDS_SELECTED_PATHS_PROPERTY, oldValue,
newValue);
|
public void | setInvokesStopCellEditing(boolean newValue)Determines what happens when editing is interrupted by selecting
another node in the tree, a change in the tree's data, or by some
other means. Setting this property to true causes the
changes to be automatically saved when editing is interrupted.
Fires a property change for the INVOKES_STOP_CELL_EDITING_PROPERTY.
boolean oldValue = invokesStopCellEditing;
invokesStopCellEditing = newValue;
firePropertyChange(INVOKES_STOP_CELL_EDITING_PROPERTY, oldValue,
newValue);
|
public void | setLargeModel(boolean newValue)Specifies whether the UI should use a large model.
(Not all UIs will implement this.) Fires a property change
for the LARGE_MODEL_PROPERTY.
boolean oldValue = largeModel;
largeModel = newValue;
firePropertyChange(LARGE_MODEL_PROPERTY, oldValue, newValue);
|
public void | setLeadSelectionPath(javax.swing.tree.TreePath newPath)Sets the path identifies as the lead. The lead may not be selected.
The lead is not maintained by JTree ,
rather the UI will update it.
TreePath oldValue = leadPath;
leadPath = newPath;
firePropertyChange(LEAD_SELECTION_PATH_PROPERTY, oldValue, newPath);
|
public void | setModel(javax.swing.tree.TreeModel newModel)Sets the TreeModel that will provide the data.
clearSelection();
TreeModel oldModel = treeModel;
if(treeModel != null && treeModelListener != null)
treeModel.removeTreeModelListener(treeModelListener);
if (accessibleContext != null) {
if (treeModel != null) {
treeModel.removeTreeModelListener((TreeModelListener)accessibleContext);
}
if (newModel != null) {
newModel.addTreeModelListener((TreeModelListener)accessibleContext);
}
}
treeModel = newModel;
clearToggledPaths();
if(treeModel != null) {
if(treeModelListener == null)
treeModelListener = createTreeModelListener();
if(treeModelListener != null)
treeModel.addTreeModelListener(treeModelListener);
// Mark the root as expanded, if it isn't a leaf.
if(treeModel.getRoot() != null &&
!treeModel.isLeaf(treeModel.getRoot())) {
expandedState.put(new TreePath(treeModel.getRoot()),
Boolean.TRUE);
}
}
firePropertyChange(TREE_MODEL_PROPERTY, oldModel, treeModel);
invalidate();
|
public void | setRootVisible(boolean rootVisible)Determines whether or not the root node from
the TreeModel is visible.
boolean oldValue = this.rootVisible;
this.rootVisible = rootVisible;
firePropertyChange(ROOT_VISIBLE_PROPERTY, oldValue, this.rootVisible);
if (accessibleContext != null) {
((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
}
|
public void | setRowHeight(int rowHeight)Sets the height of each cell, in pixels. If the specified value
is less than or equal to zero the current cell renderer is
queried for each row's height.
int oldValue = this.rowHeight;
this.rowHeight = rowHeight;
rowHeightSet = true;
firePropertyChange(ROW_HEIGHT_PROPERTY, oldValue, this.rowHeight);
invalidate();
|
public void | setScrollsOnExpand(boolean newValue)Sets the scrollsOnExpand property,
which determines whether the
tree might scroll to show previously hidden children.
If this property is true (the default),
when a node expands
the tree can use scrolling to make
the maximum possible number of the node's descendants visible.
In some look and feels, trees might not need to scroll when expanded;
those look and feels will ignore this property.
boolean oldValue = scrollsOnExpand;
scrollsOnExpand = newValue;
scrollsOnExpandSet = true;
firePropertyChange(SCROLLS_ON_EXPAND_PROPERTY, oldValue,
newValue);
|
public void | setSelectionInterval(int index0, int index1)Selects the nodes between index0 and index1, inclusive.
TreePath[] paths = getPathBetweenRows(index0, index1);
this.getSelectionModel().setSelectionPaths(paths);
|
public void | setSelectionModel(javax.swing.tree.TreeSelectionModel selectionModel)Sets the tree's selection model. When a null value is
specified an emtpy
selectionModel is used, which does not allow selections.
if(selectionModel == null)
selectionModel = EmptySelectionModel.sharedInstance();
TreeSelectionModel oldValue = this.selectionModel;
if (this.selectionModel != null && selectionRedirector != null) {
this.selectionModel.removeTreeSelectionListener
(selectionRedirector);
}
if (accessibleContext != null) {
this.selectionModel.removeTreeSelectionListener((TreeSelectionListener)accessibleContext);
selectionModel.addTreeSelectionListener((TreeSelectionListener)accessibleContext);
}
this.selectionModel = selectionModel;
if (selectionRedirector != null) {
this.selectionModel.addTreeSelectionListener(selectionRedirector);
}
firePropertyChange(SELECTION_MODEL_PROPERTY, oldValue,
this.selectionModel);
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
Boolean.valueOf(false), Boolean.valueOf(true));
}
|
public void | setSelectionPath(javax.swing.tree.TreePath path)Selects the node identified by the specified path. If any
component of the path is hidden (under a collapsed node), and
getExpandsSelectedPaths is true it is
exposed (made viewable).
getSelectionModel().setSelectionPath(path);
|
public void | setSelectionPaths(javax.swing.tree.TreePath[] paths)Selects the nodes identified by the specified array of paths.
If any component in any of the paths is hidden (under a collapsed
node), and getExpandsSelectedPaths is true
it is exposed (made viewable).
getSelectionModel().setSelectionPaths(paths);
|
public void | setSelectionRow(int row)Selects the node at the specified row in the display.
int[] rows = { row };
setSelectionRows(rows);
|
public void | setSelectionRows(int[] rows)Selects the nodes corresponding to each of the specified rows
in the display. If a particular element of rows is
< 0 or >= getRowCount , it will be ignored.
If none of the elements
in rows are valid rows, the selection will
be cleared. That is it will be as if clearSelection
was invoked.
TreeUI ui = getUI();
if(ui != null && rows != null) {
int numRows = rows.length;
TreePath[] paths = new TreePath[numRows];
for(int counter = 0; counter < numRows; counter++) {
paths[counter] = ui.getPathForRow(this, rows[counter]);
}
setSelectionPaths(paths);
}
|
public void | setShowsRootHandles(boolean newValue)Sets the value of the showsRootHandles property,
which specifies whether the node handles should be displayed.
The default value of this property depends on the constructor
used to create the JTree .
Some look and feels might not support handles;
they will ignore this property.
boolean oldValue = showsRootHandles;
TreeModel model = getModel();
showsRootHandles = newValue;
showsRootHandlesSet = true;
firePropertyChange(SHOWS_ROOT_HANDLES_PROPERTY, oldValue,
showsRootHandles);
if (accessibleContext != null) {
((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
}
invalidate();
|
public void | setToggleClickCount(int clickCount)Sets the number of mouse clicks before a node will expand or close.
The default is two.
int oldCount = toggleClickCount;
toggleClickCount = clickCount;
firePropertyChange(TOGGLE_CLICK_COUNT_PROPERTY, oldCount,
clickCount);
|
public void | setUI(javax.swing.plaf.TreeUI ui)Sets the L&F object that renders this component.
if ((TreeUI)this.ui != ui) {
settingUI = true;
uiTreeExpansionListener = null;
try {
super.setUI(ui);
}
finally {
settingUI = false;
}
}
|
void | setUIProperty(java.lang.String propertyName, java.lang.Object value)
if (propertyName == "rowHeight") {
if (!rowHeightSet) {
setRowHeight(((Number)value).intValue());
rowHeightSet = false;
}
} else if (propertyName == "scrollsOnExpand") {
if (!scrollsOnExpandSet) {
setScrollsOnExpand(((Boolean)value).booleanValue());
scrollsOnExpandSet = false;
}
} else if (propertyName == "showsRootHandles") {
if (!showsRootHandlesSet) {
setShowsRootHandles(((Boolean)value).booleanValue());
showsRootHandlesSet = false;
}
} else {
super.setUIProperty(propertyName, value);
}
|
public void | setVisibleRowCount(int newCount)Sets the number of rows that are to be displayed.
This will only work if the tree is contained in a
JScrollPane ,
and will adjust the preferred size and size of that scrollpane.
int oldCount = visibleRowCount;
visibleRowCount = newCount;
firePropertyChange(VISIBLE_ROW_COUNT_PROPERTY, oldCount,
visibleRowCount);
invalidate();
if (accessibleContext != null) {
((AccessibleJTree)accessibleContext).fireVisibleDataPropertyChange();
}
|
public void | startEditingAtPath(javax.swing.tree.TreePath path)Selects the node identified by the specified path and initiates
editing. The edit-attempt fails if the CellEditor
does not allow
editing for the specified item.
TreeUI tree = getUI();
if(tree != null)
tree.startEditingAtPath(this, path);
|
public boolean | stopEditing()Ends the current editing session.
(The DefaultTreeCellEditor
object saves any edits that are currently in progress on a cell.
Other implementations may operate differently.)
Has no effect if the tree isn't being edited.
Note:
To make edit-saves automatic whenever the user changes
their position in the tree, use {@link #setInvokesStopCellEditing}.
TreeUI tree = getUI();
if(tree != null)
return tree.stopEditing(this);
return false;
|
public void | treeDidChange()Sent when the tree has changed enough that we need to resize
the bounds, but not enough that we need to remove the
expanded node set (e.g nodes were expanded or collapsed, or
nodes were inserted into the tree). You should never have to
invoke this, the UI will invoke this as it needs to.
revalidate();
repaint();
|
private void | unarchiveExpandedState(java.lang.Object state)Updates the expanded state of nodes in the tree based on the
previously archived state state .
if(state instanceof Vector) {
Vector paths = (Vector)state;
for(int counter = paths.size() - 1; counter >= 0; counter--) {
Boolean eState = (Boolean)paths.elementAt(counter--);
TreePath path;
try {
path = getPathForIndexs((int[])paths.elementAt(counter));
if(path != null)
expandedState.put(path, eState);
} catch (Error error) {}
}
}
|
public void | updateUI()Notification from the UIManager that the L&F has changed.
Replaces the current UI object with the latest version from the
UIManager .
setUI((TreeUI)UIManager.getUI(this));
invalidate();
|
private void | writeObject(java.io.ObjectOutputStream s)
Vector values = new Vector();
s.defaultWriteObject();
// Save the cellRenderer, if its Serializable.
if(cellRenderer != null && cellRenderer instanceof Serializable) {
values.addElement("cellRenderer");
values.addElement(cellRenderer);
}
// Save the cellEditor, if its Serializable.
if(cellEditor != null && cellEditor instanceof Serializable) {
values.addElement("cellEditor");
values.addElement(cellEditor);
}
// Save the treeModel, if its Serializable.
if(treeModel != null && treeModel instanceof Serializable) {
values.addElement("treeModel");
values.addElement(treeModel);
}
// Save the selectionModel, if its Serializable.
if(selectionModel != null && selectionModel instanceof Serializable) {
values.addElement("selectionModel");
values.addElement(selectionModel);
}
Object expandedData = getArchivableExpandedState();
if(expandedData != null) {
values.addElement("expandedState");
values.addElement(expandedData);
}
s.writeObject(values);
if (getUIClassID().equals(uiClassID)) {
byte count = JComponent.getWriteObjCounter(this);
JComponent.setWriteObjCounter(this, --count);
if (count == 0 && ui != null) {
ui.installUI(this);
}
}
|