CheckboxTree

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.

Re: CheckboxTree

Postby JIDE Support » Fri Sep 11, 2009 3:21 pm

You just insert tree node to the original tree model, just like what you were doing before in a regular JTree.

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

Re: CheckboxTree

Postby hemna » Fri Sep 11, 2009 4:12 pm

Code: Select all
   /**
    * This method inserts a new node dynamically into the tree.
    * Since we only support 2 level tree...we accept 2 params.
    *
    * @param String
    * @param String
    */
   protected void insertNewTreeNode(String level1NodeStr, String level2NodeStr) {
      //first we need to see if level1NodeStr already exists in the tree
      TreeModel myTreeModel = checkBoxTree.getModel();
      DefaultMutableTreeNode level1Node = findLevel1NodeInTree(level1NodeStr);
      
      if (level1Node == null) {
         //levelNodeStr doesn't exist in the tree.
         //we need to add it to the root.
         level1Node = new DefaultMutableTreeNode(level1NodeStr);
         DefaultMutableTreeNode level2Node = new DefaultMutableTreeNode(level2NodeStr);
         level1Node.add(level2Node);
                  
         DefaultMutableTreeNode root = (DefaultMutableTreeNode)myTreeModel.getRoot();
         root.add(level1Node);         
      } else {
         //add the level2NodeStr to the level1Node
         DefaultMutableTreeNode level2Node = new DefaultMutableTreeNode(level2NodeStr);
         level1Node.add(level2Node);
      }      
      
      checkBoxTree.setModel(myTreeModel);
   }
   
   
   /**
    * This method tries to find a level1Node in the tree.
    *
    * @return
    *
    */   
   protected DefaultMutableTreeNode findLevel1NodeInTree(String nodeStr) {
      DefaultMutableTreeNode node = null;
      
      TreeModel myTreeModel = checkBoxTree.getModel();
      Object root = myTreeModel.getRoot();
      int rootChildCount = myTreeModel.getChildCount(root);
      for (int i = 0; i < rootChildCount; i++) {
         DefaultMutableTreeNode child = (DefaultMutableTreeNode)myTreeModel.getChild(root, i);
         
         if (child.getUserObject().toString().compareToIgnoreCase(nodeStr) == 0) {
            node = child;
            break;
         }                  
      }      
      
      return node;
   }



So that is my code for inserting a node. When I run the applet in eclipse, I can see the new node being added into the existing nodes that I find,
but they don't show up in the tree from what I can see.

before_add.png
This is a screenshot of just prior to me adding the new entry.
before_add.png (9.28 KiB) Viewed 13178 times


after_add.png
This is after I a call the insertNewTreeNode() method.
after_add.png (8.89 KiB) Viewed 13178 times
hemna
 
Posts: 37
Joined: Wed Jul 29, 2009 10:27 am

Re: CheckboxTree

Postby JIDE Support » Fri Sep 11, 2009 4:19 pm

That's not the correct way. You should use DefaultTreeModel#insertNodeInto method.
JIDE Software Technical Support Team
JIDE Support
Site Admin
 
Posts: 37219
Joined: Sun Sep 14, 2003 10:49 am

Re: CheckboxTree

Postby hemna » Fri Sep 11, 2009 4:27 pm

excellent thank you. That worked like a charm.
hemna
 
Posts: 37
Joined: Wed Jul 29, 2009 10:27 am

Re: CheckboxTree

Postby CHEM_Eugene » Tue Sep 20, 2011 2:20 am

Could you help me with my problem? I need to have ability to disable some elements of tree. They must be unselectable.

How I can do it?

Sorry, I have found answer: It needs to override method CheckBoxTree.isCheckBoxEnabled(final TreePath path)
CHEM_Eugene
 
Posts: 4
Joined: Thu Sep 15, 2011 5:49 am

Re: CheckboxTree

Postby JIDE Support » Tue Sep 20, 2011 9:39 am

Glad to know that you have figured out the solution.

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

Previous

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

Who is online

Users browsing this forum: No registered users and 9 guests

cron