【问题标题】:How to make new tree which contains subtree from JTree?如何制作包含 JTree 子树的新树?
【发布时间】:2019-05-28 22:00:40
【问题描述】:

基本上我需要递归方面的帮助。关键是我正在尝试制作显示带有复选框的 JTree 的对话框,并且我做到了(在此处复制最流行的代码)。但我只能从主框架复制整棵树,我需要选择组件作为新树的根。所以我想我必须为一棵新树构建新的 DefaultTreeModel。

我尝试了我发现的每一个例子......从这里到任何地方。我看到人们使用递归,但我无法应用以正确方式给出的代码,或者它们不适合。

So this is my dialog class where I make new tree

It works when I try to check whole tree copied

But when I try to check copied subtree this is the result

This is the line with NullPointerException, somehow nodesCheckingState.get(tp) returns null, nodeCheckingState is hash map

我从这里粘贴了整个代码 Java Swing: Need a good quality developed JTree with checkboxes

【问题讨论】:

  • 添加您尝试过的代码,特别是您遇到问题的地方。
  • @AndrewMortimer 做到了

标签: java swing jtree


【解决方案1】:

我解决了!我需要做的就是将新根的父级设置为空。 :)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-17
    • 2015-04-22
    • 1970-01-01
    • 1970-01-01
    • 2013-05-28
    • 2012-01-11
    • 1970-01-01
    相关资源
    最近更新 更多