Results 1 to 4 of 4
  1. #1
    aparnakumari is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default selecting checkbox of parent node not resulting into selction of checkbox of all desc

    Hi All,
    Please help me! My code is working fine for parent and child case but child's child not get selected when parent is checked. Please guide me so that I can correct/add in my below written part of my code.
    {code}

    tree.setModel(new DefaultTreeModel(rootNode1) {
    public void valueForPathChanged(TreePath path, Object newValue) {
    Object currNode = path.getLastPathComponent();
    super.valueForPathChanged(path, newValue);
    if ((currNode != null) && (currNode instanceof DefaultMutableTreeNode)) {
    DefaultMutableTreeNode editedNode = (DefaultMutableTreeNode) currNode;
    CheckBoxNode newCBN = (CheckBoxNode) newValue;
    CheckBoxNode newCBN1 = (CheckBoxNode) newValue;
    if (!editedNode.isLeaf()) {
    int i=0;
    //for (int i = 0; i < editedNode.getChildCount(); i++) {
    while(i < editedNode.getChildCount()){
    System.out.println("child count root"+editedNode.getChildCount());
    System.out.println("child count root i"+i);
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getChildAt(i);
    CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
    cbn.setSelected(newCBN.isSelected());
    i++;
    }

    }
    else{
    boolean isAllChiledSelected = true;
    for (int i = 0; i < editedNode.getParent().getChildCount(); i++) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent().getChildAt(i);
    CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
    if(!cbn.isSelected()){
    isAllChiledSelected = false;
    }
    }

    if(isAllChiledSelected){
    DefaultMutableTreeNode node = (DefaultMutableTreeNode)editedNode.getParent();
    CheckBoxNode cbn = (CheckBoxNode) node.getUserObject();
    cbn.setSelected(isAllChiledSelected);
    }
    }

    if (!newCBN.isSelected()) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent();
    if (node.getUserObject() instanceof CheckBoxNode)
    ((CheckBoxNode) node.getUserObject()).setSelected(false);
    }

    if (!newCBN1.isSelected()) {
    DefaultMutableTreeNode node = (DefaultMutableTreeNode) editedNode.getParent();
    if (node.getUserObject() instanceof CheckBoxNode)
    ((CheckBoxNode) node.getUserObject()).setSelected(false);
    }
    }
    }
    });
    {code}

  2. #2
    aparnakumari is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default Solved

    Hi All,

    I got the solution of the same by my own.

    Thanks

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default

    So don't you think you should inform the members of the other forum that the problem no longer exists?
    Swing - checkbox in parent nodes are not getting selected

    db

  4. #4
    aparnakumari is offline Member
    Join Date
    Jul 2010
    Posts
    3
    Rep Power
    0

    Default Yes

    Hi db,
    I agree with your point. Actually this page was already opened when I got my things working so immediately I wrote about it. For another forum also I wrote but few hours late as I had to go somewhere for a personal work. Sorry, for any inconvenience.

    Aparna

Similar Threads

  1. checkbox question
    By HellRider in forum AWT / Swing
    Replies: 1
    Last Post: 02-09-2010, 03:35 PM
  2. CheckBox
    By boss in forum NetBeans
    Replies: 3
    Last Post: 01-17-2010, 04:51 AM
  3. CheckBox in JTable
    By nikosa in forum AWT / Swing
    Replies: 1
    Last Post: 08-05-2009, 05:01 AM
  4. Jtree with checkbox
    By msankar.ravi in forum AWT / Swing
    Replies: 1
    Last Post: 07-09-2009, 11:25 PM
  5. checkbox
    By Alan in forum AWT / Swing
    Replies: 3
    Last Post: 05-18-2007, 10:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •