简体   繁体   English

BinaryTree到JTree?

[英]BinaryTree to JTree?

I am trying to convert a BinaryTree which is made of Nodes into a JTree for a GUI view. 我正在尝试将由节点组成的BinaryTree转换为用于GUI视图的JTree。 I figure this is the pseudo-code I need: 我认为这是我需要的伪代码:

if root == null
        set data  as root
 if data < root
        if leftNode == null
            add data to left node
        if data < leftNode
            add data to left node
        if data > leftNode
            add data to right node
 if data > root
        if rightNode == null
            add data to right node
        if data < right node
            add data to left node
        if data > right node
            add data to right node

Any ideas on how to actually implement this pseudo code? 关于如何实际实现此伪代码的任何想法? I know there needs to be some recursion to get this to affect all the child nodes. 我知道需要进行一些递归才能影响所有子节点。

Instead of traversing your tree, implement the TreeModel interface so that it fetches the tree's nodes as requested by the JTree . 而不是遍历您的树,而是实现TreeModel接口,以便它根据JTree请求获取树的节点。 Examples may be found in Creating a Data Model . 示例可以在创建数据模型中找到

Addendum: FileSystemModel is a related example. 附录: FileSystemModel是一个相关示例。

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

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