带复选框的 JTree [英] JTree with checkboxes
问题描述
我需要向 JTree 添加复选框.自定义 TreeCellRenderer/TreeCellEditor 似乎是正确的方法.到目前为止,我使用了本网页中的 CheckBoxNodeRenderer 方法.除了两件事外,它可以正常工作:
I need to add checkboxes to a JTree. A custom TreeCellRenderer/TreeCellEditor seems like the right approach. So far I used the CheckBoxNodeRenderer approach in this webpage. It works OK except for two things:
- 复选框上方+下方有额外的空格;我想保持它与常规 JTree 相同.
- 我想区分单击复选框本身(应该尝试切换复选框)和单击与复选框关联的文本(这应该允许事件侦听器将其解释为单击相应的树节点和采取任何适当的行动)
有没有办法做这些事情?我四处寻找带有复选框的 JTrees,找不到太多.JIDE 看起来不错,但在这种情况下我需要使用免费的开源软件(GPL 不行,LGPL 可以).(或创建我自己的复选框树)
is there a way to do these things? I looked around for JTrees with checkboxes, can't find much. JIDE looks good but I need to use free open-source software (GPL is not ok, LGPL is ok) in this case. (or create my own checkbox tree)
推荐答案
至于 #2,您可以将面板设为编辑器/渲染器,并在复选框中添加标签 - 标签将是文本,并且复选框不会添加文本.
As for #2, you could make a panel be the editor/renderer, and add a label along with the checkbox - the label would be the text, and the check box would not have the text added to it.
这篇关于带复选框的 JTree的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!