在JTree中为DefaultMutableTreeNode分配唯一ID? [英] Assign unique ID to a DefaultMutableTreeNode in a JTree?

查看:220
本文介绍了在JTree中为DefaultMutableTreeNode分配唯一ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Jtree,可以向其中添加新的Node.我需要为每个新节点分配一个唯一的ID. 我当时在考虑扩展DefaultMutableTreeNode类,但是我猜想它没有用,或者我做错了.

I have a Jtree that I can add new Nodes to. I need to assign a unique ID to each new node. I was thinking of extending the DefaultMutableTreeNode Class but I guess it didn't work or I did it wrong.

所以,我该怎么做.一个例子会很好.谢谢.

So, how can I do this. An example would be nice. Thanks.

推荐答案

好,我弄清楚了,它起作用了:) 我引爆了DefaultMutableTreeNode:

OK I figured it out and it WORKS :) I extednded DefaultMutableTreeNode:

 public class MyTreeNode extends DefaultMutableTreeNode {

    public int ID;

    public void setID(int ID) {
        this.ID = ID;
    }

    public MyTreeNode(String title) {
        setUserObject(title);
    }
}

这篇关于在JTree中为DefaultMutableTreeNode分配唯一ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆