CheckBoxTree-Need to display checkbox only for leaf nodes

This is the forum for JIDE Common Layer which is open sourced at https://github.com/jidesoft/jide-oss. Please note, JIDE technical support doesn't monitor this forum as often as other forums. Please consider subscribe for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

Moderator: JIDE Support

Forum rules
Community driven forum for open source JIDE Common Layer. JIDE technical support doesn't monitor this forum as often as other forums. If you only use JIDE Common Layer, please consider subscribing for technical support for JIDE Common Layer so that you can use customer only forum to get a timely response.

CheckBoxTree-Need to display checkbox only for leaf nodes

Postby mandar.j » Fri Jul 27, 2012 1:10 am

Hi,

I am trying to use CheckBoxTree and in that I would like to display checkbox only for those nodes who don't have any child node i.e. only for leaf nodes. But somehow I am not getting how to set this behaviour. The nodes in tree who have child node should display as a normal folder(with expand capability) icon without checkbox for the same.

Any idea on how to achieve this behaviour?

Any help would be appreciated.

Code snippet:
Code: Select all
DefaultMutableTreeNode rootNode = new DefaultMutableTreeNode(nodeName);
DefaultMutableTreeNode childeNode1 = new DefaultMutableTreeNode(nodeName1);
DefaultMutableTreeNode childeNode2 = new DefaultMutableTreeNode(nodeName2);
DefaultMutableTreeNode grandChildeNode3 = new DefaultMutableTreeNode(nodeName3);

rootNode.add(childeNode1);
rootNode.add(childeNode2);
childeNode2.add(grandChildeNode3);

CheckBoxTree tree = new CheckBoxTree(rootNode);


Thanks,
Mandar
mandar.j
 
Posts: 8
Joined: Fri Jul 27, 2012 12:57 am

Re: CheckBoxTree-Need to display checkbox only for leaf node

Postby JIDE Support » Fri Jul 27, 2012 9:15 am

Please give the following code a try.
Code: Select all
        _tree = new CheckBoxTree(treeModel) {
            @Override
            public boolean isCheckBoxVisible(TreePath path) {
                return ((DefaultMutableTreeNode) path.getLastPathComponent()).isLeaf();
            }
        };

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree-Need to display checkbox only for leaf node

Postby mandar.j » Fri Jul 27, 2012 10:27 am

Fantastic. It worked !!

Thanks a lot.

Mandar
mandar.j
 
Posts: 8
Joined: Fri Jul 27, 2012 12:57 am

Re: CheckBoxTree-Need to display checkbox only for leaf node

Postby kenyca » Thu Dec 13, 2012 12:40 am

Hello I use the JIDE Package to create a JTree with Checkbox, i want that only one leaf node have to be checked at the same time( that mean the leaf node work like radio button). The parent of the leaf node can be arbitrary checked. can anybody help me?
Thanks in advance

kenyca
kenyca
 
Posts: 4
Joined: Wed Dec 12, 2012 7:29 am

Re: CheckBoxTree-Need to display checkbox only for leaf node

Postby JIDE Support » Thu Dec 13, 2012 10:06 am

Please invoke yourCheckBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener() to perform your logic in the listener.

B.T.W., please try to create a separate thread when you want to start a new inquiry.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree-Need to display checkbox only for leaf node

Postby kenyca » Fri Dec 14, 2012 2:43 am

Hello,
sorry the next Time I will create a new Inquiry.
Please can you more explain how I can use the CheckBoxTree.getCheckBoxTreeSelectionModel().addTreeSelectionListener(). I use it but I get the list of Path for all Checked Button, or the last selectedNode. My idea was when a leafnode is selected look at other children of the parent node and if one is checked, i have to unchecked it. But which method can i use to checked that the children of a node are selected or not? and which method can I use to unchecked it?

Thanks in advance for your help.
kenyca
 
Posts: 4
Joined: Wed Dec 12, 2012 7:29 am

Re: CheckBoxTree-Need to display checkbox only for leaf node

Postby kenyca » Fri Dec 14, 2012 2:47 am

I wanted to say, The next Time I will create a new Thread for the new Inquiry ( my English is not very good) sorry for errors
kenyca
 
Posts: 4
Joined: Wed Dec 12, 2012 7:29 am

Re: CheckBoxTree-Need to display checkbox only for leaf node

Postby JIDE Support » Fri Dec 14, 2012 9:33 am

In that listener, please do the following:
1, keep the current selection you want to keep, for example, the last selected leaf node.
2, remove this listener, just to avoid the following steps cause endless loop.
3, clear all selections with CheckBoxTreeSelectionModel#clearSelection().
4, add the selection you kept in step 1 back with CheckBoxTreeSelectionModel#addSelectionPaths().
5, add this listener back again for future use.

Thanks,
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckBoxTree-Need to display checkbox only for leaf node

Postby kenyca » Fri Dec 14, 2012 10:43 am

Hello
thanks for the idea I will try it again monday when i worked on my project. I will give a feedback if I success.
kenyca
 
Posts: 4
Joined: Wed Dec 12, 2012 7:29 am


Return to JIDE Common Layer Open Source Project Discussion (Community Driven)

Who is online

Users browsing this forum: Google [Bot] and 9 guests