Everyone,
I am a new one for swing application.
I have to construct a JTree with JCheckBox and JRadioButton.If we select the JRadioButton at that time only one node is selected.If we select the JCheckBox we select more than one.I have attached my code.In my code I did not write for selecting the node.In my code pp1have one child i need to modify that JRadioButton to JCheckBox.And pp2 have two childs.I need to modify the pp4 JRadioButton into JCheckBox.can u please resolve it?.Otherwise send the code.

import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreePath;

public class TreeSample implements TreeSelectionListener{

public static JTree tree;
public static JScrollPane scrollPane;
public TreePath treePath;
public static JFrame frame;

public TreeSample(){
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAn dFeelClassName());
} catch (ClassNotFoundException e) {
e.printStackTrace();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
}
public static void main(String args[]) {
new TreeSample().treeCreation();
frame = new JFrame("Tree");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOS E);
frame.getContentPane().add(scrollPane);
frame.setSize(250, 250);
frame.show();
}

private JTree treeCreation() {
DefaultMutableTreeNode pp= new DefaultMutableTreeNode("pp",true);
DefaultMutableTreeNode pp1= new DefaultMutableTreeNode("pp1",true);
DefaultMutableTreeNode pp2= new DefaultMutableTreeNode("pp2",true);
DefaultMutableTreeNode pp3= new DefaultMutableTreeNode("pp3",true);
DefaultMutableTreeNode pp4= new DefaultMutableTreeNode("pp4",true);
DefaultMutableTreeNode pp5= new DefaultMutableTreeNode("pp5",true);
DefaultMutableTreeNode pp6= new DefaultMutableTreeNode("pp6",true);

pp.insert(pp1,0);
pp.insert(pp2,1);
pp1.add(pp3);
pp2.insert(pp4,0);
pp2.insert(pp5,1);
pp5.add(pp6);
tree = new JTree(configuration);
scrollPane = new JScrollPane(tree);
CheckBoxRender render = new CheckBoxRender();
tree.setCellRenderer(render);
//tree.addTreeSelectionListener(this);
return tree;
}

public void valueChanged(TreeSelectionEvent event) {
treePath = event.getNewLeadSelectionPath();
System.out.println(treePath);
}
}

import java.awt.Color;
import java.awt.Component;
import java.awt.Font;

import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JTree;
import javax.swing.UIManager;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.TreeCellRenderer;

public class CheckBoxRender extends TreeSample implements TreeCellRenderer {

private JCheckBox parentRenderer = new JCheckBox();
private JRadioButton leafRenderer = new JRadioButton();

Color selectionForeground, selectionBackground, textForeground, textBackground;

public CheckBoxRender() {
Font fontValue;
fontValue = UIManager.getFont("Tree.Font");
if (fontValue != null) {
leafRenderer.setFont(fontValue);
}
selectionForeground = UIManager.getColor("Tree.selectionForeground");
selectionBackground = UIManager.getColor("Tree.selectionBackground");
textForeground = UIManager.getColor("Tree.textForeground");
textBackground = UIManager.getColor("Tree.textBackground");
TreeSample.tree.addTreeSelectionListener(this);
}

public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean selected, boolean expanded, boolean leaf, int row,boolean hasFocus) {
Component returnValue=null;
if (leaf) {
String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, false);
leafRenderer.setText(stringValue);
if (selected) {
leafRenderer.setForeground(selectionForeground);
leafRenderer.setBackground(selectionBackground);
}
else {
leafRenderer.setForeground(textForeground);
leafRenderer.setBackground(textBackground);
}
returnValue = leafRenderer;
}
else {
String stringValue = tree.convertValueToText(value, selected, expanded, leaf, row, false);
parentRenderer.setText(stringValue);

if (selected) {
parentRenderer.setForeground(selectionForeground);
parentRenderer.setBackground(selectionBackground);
}
else {
parentRenderer.setForeground(textForeground);
parentRenderer.setBackground(textBackground);
}
returnValue= parentRenderer;
}
return returnValue;
}

public void valueChanged(TreeSelectionEvent event) {
treePath = event.getNewLeadSelectionPath();
System.out.println(treePath);
}
}

Thanks in advance my dear friends.

Regards,
P.Parthasarathi