繁体   English   中英

Jtree根据鼠标单击获取对象?

[英]Jtree get object based on mouse click?

双击鼠标时,我使用此代码片段对树执行某些操作:打开一个窗口并获取被鼠标双击的node ,但它不返回任何内容,它返回null:

MouseListener ml = new MouseAdapter() {
    public void mousePressed(MouseEvent e) {
        int selRow = contactTree.getRowForLocation(e.getX(), e.getY());
        TreePath selPath = contactTree.getPathForLocation(e.getX(), e.getY());
        System.out.println(contactTree.getEditingPath());
        Account memberToChat;
        if(selRow != -1) {
            if(e.getClickCount() == 1) {

            }
            else if(e.getClickCount() == 2) {
                new ChatWindow().setVisible(true);
                memberToChat=(Account)node.getUserObject(); // node is declared somewhere in the class as   DefaultMutableTreeNode node
                System.out.println(memberToChat.getFirstName()+" "+memberToChat.getEmail());
            }
        }
    }
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM