将“展开”按钮添加到没有子节点的JTree节点? [英] Add 'expand' button to JTree node that has no children?

查看:135
本文介绍了将“展开”按钮添加到没有子节点的JTree节点?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的JTree节点上添加'expand'按钮,以表明它们是可扩展的。问题是,在用户点击它们之前它们没有孩子(由于后台发生的处理)。

I'd like to add the 'expand' button to my JTree's nodes to indicate that they are expandable. The catch is that they have no children until the user clicks on them (due to processing that happens in the background).

我有什么方法可以将节点设置为父节点或者让孩子没有孩子而实际生孩子?

Is there any way I can set a node as a parent or having children without it actually having children?

谢谢

推荐答案

可以使用你自己的 DefaultMutableTreeNode 实现覆盖 isLeaf()

It's possible using your own DefaultMutableTreeNode implementation overriding isLeaf():


如果此节点没有子节点,则返回true。

Returns true if this node has no children.

Swing教程:JTree 4.1 Dynamic Tree 下解释它。

这篇关于将“展开”按钮添加到没有子节点的JTree节点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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