Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
254 views
in Technique[技术] by (71.8m points)

java - JTree with checkboxes

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. there's additional whitespace above + below the checkbox; I'd like to keep it the same as a regular JTree.
  2. I would like to distinguish between clicking on the checkbox itself (which should attempt to toggle the checkbox) and clicking on the text associated with the checkbox (which should allow an event listener to interpret this as clicking on the corresponding tree node and take whatever action is appropriate)

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)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I know this question has been answered already, but i just want to clear some points:

1) JIDE Common Layer is dual-licensed (GPL with classpath exception and free commercial license). This means that you can use the Common Layer Project without any licensing issues. Please check the following link to confirm: http://www.jidesoft.com/products/oss.htm. The Common Layer includes an implementation of a checkable JTree (com.jidesoft.swing.CheckBoxTree).

2) There's a blog dated from 2005 from the Master himself, Santhosh Kumar, where he explains how to implement a JTree with checkboxes with the requirements you mentioned: http://www.jroller.com/santhosh/entry/jtree_with_checkboxes. It's worth reading it, in my opinion.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.9k users

...