📄 tree.html
字号:
<td>The first method sets whether the user can edit tree nodes. By default, tree nodes are not editable. The second sets which customized editor to use. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setRootVisible(boolean)">void setRootVisible(boolean)</a> </td> <td>Set whether the tree shows the root node. The default value is false if the tree is created using one of the constructors that takes a data structure, and true otherwise. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setShowsRootHandles(boolean)">void setShowsRootHandles(boolean)</a> </td> <td>Set whether the tree shows handles for its leftmost nodes, letting you expand and collapse the nodes. The default is false. If the tree doesn't show the root node, then you should invoke <code>setShowsRootHandles(true)</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setDragEnabled(boolean)">void setDragEnabled(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getDragEnabled()">boolean getDragEnabled()</a> </td> <td>Set or get the <code>dragEnabled</code> property, which must be true to enable drag handling on this component. The default value is false. See<a class="TutorialLink" target="_top" href="../../dnd/index.html">Drag and Drop</a> for more details. </tr></table><p><table border=1> <caption><a name="selectionapi">Implementing Selection</a></caption><tr><th align=left>Method</th><th align=left>Purpose </th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#addTreeSelectionListener(javax.swing.event.TreeSelectionListener)">void addTreeSelectionListener(TreeSelectionListener)</a> </td> <td>Register a listener to detect when the a node is selected or deselected. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setSelectionModel(javax.swing.tree.TreeSelectionModel)">void setSelectionModel(TreeSelectionModel)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getSelectionModel()">TreeSelectionModel getSelectionModel()</a> </td> <td>Set or get the model used to control node selections. You can turn off node selection completely using <code>setSelectionModel(null)</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/tree/TreeSelectionModel.html#setSelectionMode(int)">void setSelectionMode(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/tree/TreeSelectionModel.html#getSelectionMode()">int getSelectionMode()</a> <br> <em>(in <code>TreeSelectionModel</code>)</em> </td> <td>Set or get the selection mode. The value can be <code>CONTIGUOUS_TREE_SELECTION</code>, <code>DISCONTIGUOUS_TREE_SELECTION</code>, or <code>SINGLE_TREE_SELECTION</code> (all defined in <code>TreeSelectionModel</code>). </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getLastSelectedPathComponent()">Object getLastSelectedPathComponent()</a> </td> <td>Get the object representing the currently selected node. This is equivalent to invoking <code>getLastPathComponent</code> on the value returned by <code>tree.getSelectionPath()</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setSelectionPath(javax.swing.tree.TreePath)">void setSelectionPath(TreePath)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getSelectionPath()">TreePath getSelectionPath()</a> </td> <td>Set or get the path to the currently selected node. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setSelectionPaths(javax.swing.tree.TreePath[])">void setSelectionPaths(TreePath[])</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getSelectionPaths()">TreePath[] getSelectionPaths()</a> </td> <td>Set or get the paths to the currently selected nodes. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setSelectionPath(javax.swing.tree.TreePath)">void setSelectionPath(TreePath)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getSelectionPath()">TreePath getSelectionPath()</a> </td> <td>Set or get the path to the currently selected node. </td> </tr></table><p><table border=1> <caption><a name="expandapi">Showing and Hiding Nodes</a></caption><tr><th align=left>Method</th><th align=left>Purpose</th></tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#addTreeExpansionListener(javax.swing.event.TreeExpansionListener)">void addTreeExpansionListener(TreeExpansionListener)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#addTreeWillExpandListener(javax.swing.event.TreeWillExpandListener)">void addTreeWillExpandListener(TreeWillExpandListener)</a> </td> <td>Register a listener to detect when the tree nodes <em>have</em> expanded or collapsed, or <em>will be</em> expanded or collapsed, respectively. To veto an impending expansion or collapse, a <code>TreeWillExpandListener</code> can throw a <code>ExpandVetoException</code>. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#expandPath(javax.swing.tree.TreePath)">void expandPath(TreePath)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#collapsePath(javax.swing.tree.TreePath)">void collapsePath(TreePath)</a> </td> <td>Expand or collapse the specified tree path. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#scrollPathToVisible(javax.swing.tree.TreePath)">void scrollPathToVisible(TreePath)</a> </td> <td>Ensure that the node specified by the path is visible — that the path leading up to it is expanded and the node is in the scroll pane's viewing area. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#makeVisible(javax.swing.tree.TreePath)">void makeVisible(TreePath)</a> </td> <td>Ensure that the node specified by the path is viewable — that the path leading up to it is expanded. The node might not end up within the viewing area. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setScrollsOnExpand(boolean)">void setScrollsOnExpand(boolean)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getScrollsOnExpand()">boolean getScrollsOnExpand()</a> </td> <td>Set or get whether the tree attempts to scroll to show previous hidden nodes. The default value is true. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#setToggleClickCount(int)">void setToggleClickCount(int)</a> <br><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getToggleClickCount()">int getToggleClickCount()</a> </td> <td>Set or get the number of mouse clicks before a node will expand or close. The default is two. </td> </tr> <tr> <td><a class="APILink" target="_blank" href="http://java.sun.com/javase/6/docs/api/javax/swing/JTree.html#getNextMatch(java.lang.String, int, javax.swing.text.Position.Bias)">TreePath getNextMatch(String, int, Position.Bias)</a> </td> <td>Return the <code>TreePath</code> to the next tree element that begins with the specific prefix. </td> </tr></table></blockquote><h3><a name="eg">Examples that Use Trees</a></h3><blockquote>This table lists examples that use <code>JTree</code>and where those examples are described.<p><table><tr><th align=left> Example</th><th align=left> Where Described</th><th align=left> Notes</th></tr><tr><td> <a href="examples/index.html#TreeDemo">TreeDemo</a></td><td> <a href="#create">Creating a Tree</a>, <a href="#select">Responding to Node Selection</a>, <a href="#display">Customizing a Tree's Display</a></td><td> Creates a tree that responds to user selections. It also has code for customizing the line style for the Java look and feel.</td></tr><tr><td> <a href="examples/index.html#TreeIconDemo">TreeIconDemo</a></td><td> <a href="#display">Customizing a Tree's Display</a></td><td> Adds a custom leaf icon to TreeDemo.</td></tr><tr><td> <a href="examples/index.html#TreeIconDemo2">TreeIconDemo2</a></td><td> <a href="#display">Customizing a Tree's Display</a></td><td> Customizes certain leaf icons and also provides tool tips for certain tree nodes.</td></tr><tr><td><a href="examples/index.html#DynamicTreeDemo">DynamicTreeDemo</a></td><td> <a href="#dynamic">Dynamically Changing a Tree</a></td><td> Illustrates adding and removing nodes from a tree. Also allows editing of node text.</td></tr><tr><td> <a href="examples/index.html#GenealogyExample">GenealogyExample</a></td><td> <a href="#data">Creating a Data Model</a></td><td> Implements a custom tree model and custom node type.</td></tr><tr><td> <a href="../events/examples/index.html#TreeExpandEventDemo">TreeExpandEventDemo</a></td><td> <a class="TutorialLink" target="_top" href="../events/treeexpansionlistener.html">How to Write a Tree Expansion Listener</a></td><td> Shows how to detect node expansions and collapses.</td></tr><tr><td> <a href="../events/examples/index.html#TreeExpandEventDemo2">TreeExpandEventDemo2</a></td><td> <a class="TutorialLink" target="_top" href="../events/treewillexpandlistener.html">How to Write a Tree-Will-Expand Listener</a></td><td> Shows how to veto node expansions.</td></tr><tr><td> TreeTable, TreeTable II, Editable JTreeTable</td><td> <a class="OutsideLink" target="_blank" href="http://java.sun.com/products/jfc/tsc/articles/treetable1/index.html">Creating TreeTables in Swing</a>,<a class="OutsideLink" target="_blank" href="http://java.sun.com/products/jfc/tsc/articles/treetable2/index.html">Creating TreeTables: Part 2</a>,<a class="OutsideLink" target="_blank" href="http://java.sun.com/products/jfc/tsc/articles/bookmarks/index.html#editableJTreeTable">Editable JTreeTable</a></td><td> Examples in <em>The Swing Connection</em> that combine a tree and table to show detailed information about a hierarchy such as a file system. The tree is a renderer for the table.</td></tr></table> </blockquote> <div class=NavBit> <a target=_top href=tooltip.html>« Previous</a> • <a target=_top href=../TOC.html>Trail</a> • <a target=_top href=icon.html>Next »</a> </div> </div> <div id=Footer><div id=TagNotes> Problems with the examples? Try <a target="_blank" href=../../information/run-examples.html>Compiling and Running the Examples: FAQs</a>. <br> Complaints? Compliments? Suggestions? <a target="_blank" href="http://developer.sun.com/contact/tutorial_feedback.jsp">Give us your feedback</a>.<br><br> <a target="_blank" href="../../information/copyright.html">Copyright</a> 1995-2006 Sun Microsystems, Inc. All rights reserved. <span id=Download></span></div> </div> <div class=PrintHeaders> <b>Previous page:</b> How to Use Tool Tips <br><b>Next page:</b> How to Use Icons </div> </body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -