Search code examples
javaswingjtreejcheckbox

CheckBox Node Tree


I have a checkbox node tree using java Swing. My objective is to select all the check box nodes on the click of a button .

i.e

Pseudo Code :

on(button click){    
    Check all the check box nodes 
}

Code :

for (CheckBoxNode node_r : checkBoxRows)
{
    node_r.setSelected(true);
    frame.repaint();
}

checkBoxRows is a list containing all the parent nodes in the check box node tree .

Can you guide me the correct way of doing this ?


Solution

  • checkBoxRows is a list containing all the parent nodes

    1) no needed that, because JTree implements own TreeModel, only if is there extra Controler, then you have to implements Vector<Object>, because TreeModel is TwoDimensional by default, and List has only one dimension

    2) you can simle loops inside TreeModel with checking for JCheckBox and if returns true/false from method isSelected

    3) examples for JTree, TreeModel, JTree Renderer