JTree带有复选框 [英] JTree with checkboxes

查看:168
本文介绍了JTree带有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要向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:


  1. 在复选框上方+

  2. 我想区分点击复选框本身(应该尝试切换复选框)和点击文本(应允许事件监听器将此解释为点击相应的树节点并采取适当的任何操作)

有办法做这些事吗?我环顾四周的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屋!

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