0

我正在使用可视化工具包 Zest 创建一个图表。我首先创建一个图表,然后添加一个节点。我想向该节点添加鼠标双击事件。我尝试了以下代码,但它不起作用。是不是因为验证e.button == 3?

[...]
Graph graph = new Graph(parent, SWT.BORDER);

graph.addListener(SWT.MouseDown, new Listener() {
    public void handleEvent(Event e) {
        if (e.button == 3) {

            Menu menu = new Menu(parent);
            final MenuItem a1 = new MenuItem(menu, SWT.None);
            a1.setText("New Node");
            a1.addSelectionListener(new SelectionListener() {
                                @Override
                public void widgetSelected(SelectionEvent e) {
                                  GraphNode graphNode = new GraphNode(graph, SWT.NONE);
                                  graphNode.addListener(SWT.MouseDoubleClick, new Listener
                                         (
                                           @Override
                       public void handleEvent(Event event) {
                                               System.out.println("node created");});

                @Override
                public void widgetDefaultSelected(SelectionEvent e) {}
                    }
           }
});

谢谢

4

1 回答 1

0

尝试使用MouseAdapter而不是 untyped Listener。并覆盖它的mouseDoubleClick(MouseEvent e)方法。

更新。怎么样

graph.addMouseListener(new MouseListener(){

     @Override
     public void mouseDoubleClick(MouseEvent arg0)
     {
          // TODO Auto-generated method stub
     }
     ...
}
于 2012-04-18T10:13:25.410 回答