KJW
KJW

Reputation: 15251

get underlying node data on clicked node on JTree?

basically I am using dom4j library to render the DefaultTreeModel into JTree. DefaultTreeModel parses XML document. Each XML node contains information like attributes, name, id etc.

Basically, I add a actionlistener to this Jtree. I would like to access the underlying DefaultTreeModel node containing the node's information like attributes, name etc.

 jtree.addMouseListener(new MouseInputAdapter(){
                public void mouseClicked(final java.awt.event.MouseEvent evt) {
                    int rowLocation = tree.getRowForLocation(evt.getX(), evt.getY());                           
                            if (evt.getClickCount() == 1){
                                //get this element double clicked
                                Component dblClickedElement = tree.findComponentAt(evt.getX(), evt.getY());                     
                                                    }
                    });                
                }
            });

Upvotes: 3

Views: 916

Answers (1)

StanislavL
StanislavL

Reputation: 57421

What about this?

tree.getPathForRow(rowLocation).getLastPathComponent()

Upvotes: 3

Related Questions