添加节点时未显示 Jtree!
我在滚动窗格中有一个静态 jtree。现在我正在尝试将子项添加到jtree,它已成功添加。现在,添加的节点在 jtree 中不可见。
尝试1:我尝试过 model.reload()
DefaultTreeModel model = (DefaultTreeModel) (tree.getModel());
TreePath Path = findByName(tree, new String[]{Globals.CONS_UIAPROJECTS});
DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) Path.getLastPathComponent();
model.insertNodeInto(UIAProjectExploreDisplay.nodeProTree, pnode, pnode.getChildCount());
model.reload();
尝试2:我也尝试过tree.setModel()...
DefaultTreeModel model = (DefaultTreeModel) (tree.getModel());
TreePath Path = findByName(tree, new String[]{Globals.CONS_UIAPROJECTS});
DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) Path.getLastPathComponent();
model.insertNodeInto(UIAProjectExploreDisplay.nodeProTree, pnode, pnode.getChildCount());
DefaultTreeModel projectTreeModel = new DefaultTreeModel((DefaultMutabletreeNode) model.getRoot());
tree.setModel(projectTreeModel);
即使如此,新添加的子项也不可见。但它被添加到树中。我通过打印孩子进行了测试。 给我建议一个解决方案。
I have a static jtree in a scrollpane. And now iam trying to add child to jtree, it got added successfully. Now, the added node is not visible in the jtree.
Try 1: I have tried with model.reload()
DefaultTreeModel model = (DefaultTreeModel) (tree.getModel());
TreePath Path = findByName(tree, new String[]{Globals.CONS_UIAPROJECTS});
DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) Path.getLastPathComponent();
model.insertNodeInto(UIAProjectExploreDisplay.nodeProTree, pnode, pnode.getChildCount());
model.reload();
Try 2: I have tried with tree.setModel() too...
DefaultTreeModel model = (DefaultTreeModel) (tree.getModel());
TreePath Path = findByName(tree, new String[]{Globals.CONS_UIAPROJECTS});
DefaultMutableTreeNode pnode = (DefaultMutableTreeNode) Path.getLastPathComponent();
model.insertNodeInto(UIAProjectExploreDisplay.nodeProTree, pnode, pnode.getChildCount());
DefaultTreeModel projectTreeModel = new DefaultTreeModel((DefaultMutabletreeNode) model.getRoot());
tree.setModel(projectTreeModel);
Even then newly added child is not visible. but Its getting added in thr tree. I tested by printing the child.
Suggest me a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需尝试以下行:
检查这个简单的示例。它对我有用,并在 5 秒延迟后显示两个新节点。
Simply try the following line:
Check this simple example. It works for me and shows both new nodes after the 5 seconds delay.
我想也许你忘记在 TreeNode 的插入方法中设置新节点的父节点......这是我的代码
I think maybe you forget to set your new Node's parent in your TreeNode's insert method...here is my code