Results 1 to 4 of 4
- 07-26-2010, 12:18 PM #1
Member
- Join Date
- Jul 2010
- Posts
- 3
- Rep Power
- 0
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}
- 07-27-2010, 07:57 AM #2
Member
- Join Date
- Jul 2010
- Posts
- 3
- Rep Power
- 0
Solved
Hi All,
I got the solution of the same by my own.
Thanks
- 07-27-2010, 09:40 AM #3
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
- 07-27-2010, 09:52 AM #4
Member
- Join Date
- Jul 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
checkbox question
By HellRider in forum AWT / SwingReplies: 1Last Post: 02-09-2010, 03:35 PM -
CheckBox
By boss in forum NetBeansReplies: 3Last Post: 01-17-2010, 04:51 AM -
CheckBox in JTable
By nikosa in forum AWT / SwingReplies: 1Last Post: 08-05-2009, 05:01 AM -
Jtree with checkbox
By msankar.ravi in forum AWT / SwingReplies: 1Last Post: 07-09-2009, 11:25 PM -
checkbox
By Alan in forum AWT / SwingReplies: 3Last Post: 05-18-2007, 10:10 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks