如何在java中重新填充或重新加载jtree [英] How to refilll or reload a jtree in java

查看:132
本文介绍了如何在java中重新填充或重新加载jtree的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在框架内有2个JTree A和B. l使用通过活动目录获取的计算机名称填充树A.当我在树A中选择一台PC时(例如,如果选择PC-1),我将获得PC-1中的所有文件夹并使用这些文件夹来填充(创建)树B.如果我选择另一台PC,则会发生这种情况。 (PC-2),树B的内容(以前在PC-1中显示)不清楚PC-2的内容在树B上显示(填充)。



我想要实现的是,当我在树A中选择PC-1时,它将填充树B,当我选择PC-2时,树B内容(通过PC-1)将清除PC-2的内容以绘制树B.



l尝试了三种不同的方法,如重新加载,重新绘制,设置为null,无效。



l需要帮助。



我尝试了什么:



l have 2 JTrees A and B, inside a frame. l fill tree A with computers names gotten through the active directory. When l select a PC in tree A(e.g, lemme say l select PC-1), l get all the folders in the PC-1 and use the folders to fill(create) tree B. It happens that if l select another PC(PC-2), the contents of tree B (that was showing before from PC-1) doesn't clear for the contents of the PC-2 to show(fill) on tree B.

what l want to achieve is that, when l select PC-1 in tree A, it will fill tree B, and when l select PC-2, the tree B contents(by PC-1) will clear for the contents of PC-2 to paint the tree B.

l have tried three different approaches like reloading, repainting, setting to null, none works.

l need a help.

What I have tried:

DefaultTreeModel defMod1 = (DefaultTreeModel)jTree1.getModel();                 
defMod1.reload();
jTree1.repaint();
defMod1.setRoot(null);

推荐答案

参见如何使用树(Java™教程) [ ^ ]


这篇关于如何在java中重新填充或重新加载jtree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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