简体   繁体   English

DefaultMutableTreeNode中的isRoot()

[英]isRoot() in DefaultMutableTreeNode

Why there is an isRoot() function in DefaultMutableTreeNode? 为什么在DefaultMutableTreeNode中有一个isRoot()函数? I ask because I have a Class that extends DefaultMutableTreeNode. 我问是因为我有一个扩展DefaultMutableTreeNode的类。 I would like to be able to use a single instance of this class in multiple different JTree objects. 我希望能够在多个不同的JTree对象中使用此类的单个实例。 However, it would seem that isRoot() is a question I should be asking the tree object itself. 但是,似乎isRoot()是我应该询问树对象本身的问题。 Can anyone provide any insight as to why this function exists at a node level instead of the tree level? 谁能提供任何关于为什么此功能存在于节点级别而不是树级别的见解?

The tree object can't be the root of the tree; 树对象不能是树的根。 the JTree object isn't a node. JTree对象不是节点。

DefaultMutableTreeNode is designed to facilitate recursive traversal of the tree. DefaultMutableTreeNode旨在促进树的递归遍历。 Since a recursive method processing the tree will only have access to one node (and its subsequent nodes) at a time, the only way for the method to distinguish the root of the tree is for the nodes to inidivdually keep track of whether or not they are the root of the tree. 由于处理树的递归方法一次只能访问一个节点(及其后继节点),因此该方法区分树根的唯一方法是让节点分别跟踪它们是否是树的根。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM