【问题标题】:Jtree get object based on mouse click?Jtree根据鼠标点击获取对象?
【发布时间】:2013-01-15 22:30:06
【问题描述】:

当鼠标双击时,我使用此代码片段在树上执行一些操作:打开一个窗口并获取鼠标双击的node,但它没有返回任何内容,它返回空:

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());
            }
        }
    }
};

【问题讨论】:

  • 节点已“声明”,很好。但是它在哪里设置为当前选择?您还提到“返回null”。那个return语句在哪里?你应该澄清你的问题。

标签: java swing selection jtree


【解决方案1】:
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多