开发者

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. 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜