在Java GUI中更新JTree [英] updating JTree in java GUI
本文介绍了在Java GUI中更新JTree的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在GUI中使用了JTree并将其添加到JFrame中.当我想更新它并在程序的另一部分中更改它的节点时(在程序运行时,作为执行的操作),我尝试添加新节点或删除节点.但是我的界面没有改变.请给我建议解决方案.
I used a JTree in my GUI and added it to a JFrame. When I want to update it and change it's nodes in another part of my program (while program is running, as an action performed) I try to add new nodes, or remove nodes to it; But my interface doesn't change. Please suggest me a solution.
致谢
推荐答案
除了insertNodeInto建议之外,您还可以使用:
In addition to the insertNodeInto suggestion you can also use:
DefaultTreeModel model = (DefaultTreeModel)tree.getModel();
DefaultMutableTreeNode root = (DefaultMutableTreeNode)model.getRoot();
root.add(new DefaultMutableTreeNode("another_child"));
model.reload(root);
这篇关于在Java GUI中更新JTree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文