Hi all,
I have a very small problem in JTree.
The JTree is with checkbox.When ever I select on the node the simultaneous chechbox is selected.
But some time with the same operation the checkbox is not selected.
Here,I attache the part of code which is responsible for my problem.
public void mouseClickedNodeSelectionListener(MouseEvent e)
{
int x = e.getX();
int y = e.getY();
int row = tree.getRowForLocation(x, y);
TreePath path = tree.getPathForRow(row);
//TreePath path = tree.getSelectionPath();
if (path != null) {
if(/*e.getClickCount()==1 &&*/ ElmsConstants.isDoubleClicked)
{
if(lastPath!=null)
{
tree.setSelectionPath(lastPath);
}
return;
}
lastPath = path;
CheckNode node = (CheckNode) path.getLastPathComponent();
int selectedId = 0;
if(node.getElmsData()!=null)
{
selectedId = (node.getElmsData().getId()).intValue();
}
if(lastSelectedId==selectedId)
{
boolean isSelected = !(node.isSelected());
node.setSelected(isSelected);
tree.updateUI();
((DefaultTreeModel) tree.getModel()).nodeChanged(node);
if (row == 0) {
try{
tree.revalidate();
tree.repaint();
}catch(Exception eE)
{
System.out.println("Exception in Tree repaint");
}
}
}
lastSelectedId=selectedId;
}
}
Any Body Please help me.
Thank you,
Ananda