Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Selection Of checkbox in the JTree

843807Oct 7 2009 — edited Oct 8 2009
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
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 5 2009
Added on Oct 7 2009
4 comments
366 views