TreeModel 的自定义实现在调用 treeNodesInserted 后拒绝重新绘制

发布于 2024-09-04 20:30:46 字数 299 浏览 9 评论 0原文

我正在为 JTree 使用自定义 TreeModel。当我将新节点插入到 TreeModel 中,然后在所有 TreeModelListener 上调用 treeNodesInserted(TreeModelEvent) 时,出现问题。

我认为这个问题与 JTree.TreeModelHandler 没有对 treeNodesInserted(e) 的实现有关,只有 treeStructureChanged(e)

显然对我来说能够插入会好得多,而不是更改完整的树结构。

有解决方法吗? (我不能使用DefaultTreeModel)

I'm using a custom TreeModel for a JTree. I have an issue when I insert a new node into my TreeModel, and then call treeNodesInserted(TreeModelEvent) on all my TreeModelListeners.

I think the issue has to do with the fact that JTree.TreeModelHandler has no implementation for treeNodesInserted(e), only treeStructureChanged(e)

obviously for me it would be a lot better to be able to insert, instead of a full tree structure changed.

Is there a workaround? (I can't use DefaultTreeModel)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

韶华倾负 2024-09-11 20:30:46

更多细节会有所帮助。但我也做过类似的事情,没有任何问题。就我而言,我已经让 MyTreeModel 实现了 TreeModel,并且 fireTreeInserts 函数是其中的一部分。

该函数看起来像这样(清理后的应用程序特定代码):

   public void fireTreeInsert(TreePath path, Object child) {
      Object[] children = {child};
      int index = this.getIndexOfChild(path.getLastPathComponent(), child);
      int[] indicies = {index};
      TreeModelEvent e = new TreeModelEvent(this, path, indicies, children);
      EventListener[] listeners = mTreeModel.getListeners(TreeModelListener.class);
      for (int ii = 0; ii < listeners.length; ii++) {
         ((TreeModelListener)listeners[ii]).treeNodesInserted(e);
      }
   }

Some more details would help. But I have done a similar thing with no issues. In my case I've got MyTreeModel implements TreeModel, and a fireTreeInserts function is part of it.

The function looks something like this (cleaned application specific code):

   public void fireTreeInsert(TreePath path, Object child) {
      Object[] children = {child};
      int index = this.getIndexOfChild(path.getLastPathComponent(), child);
      int[] indicies = {index};
      TreeModelEvent e = new TreeModelEvent(this, path, indicies, children);
      EventListener[] listeners = mTreeModel.getListeners(TreeModelListener.class);
      for (int ii = 0; ii < listeners.length; ii++) {
         ((TreeModelListener)listeners[ii]).treeNodesInserted(e);
      }
   }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文