开发者

get underlying node data on clicked node on JTree?

开发者 https://www.devze.com 2023-03-09 03:14 出处:网络
basically I am using dom4j library to render the DefaultTreeModel into JTree. DefaultTreeModel parses XML document. Eac开发者_如何转开发h XML node contains information like attributes, name, id etc.

basically I am using dom4j library to render the DefaultTreeModel into JTree. DefaultTreeModel parses XML document. Eac开发者_如何转开发h 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());                     
                                                    }
                    });                
                }
            });


What about this?

tree.getPathForRow(rowLocation).getLastPathComponent()
0

精彩评论

暂无评论...
验证码 换一张
取 消