我正在使用可视化工具包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) {}
}
}
});
谢谢
答案 0 :(得分:0)
尝试使用MouseAdapter
代替无类型Listener
。并覆盖其mouseDoubleClick(MouseEvent e)
方法。
UPD。怎么样
graph.addMouseListener(new MouseListener(){
@Override
public void mouseDoubleClick(MouseEvent arg0)
{
// TODO Auto-generated method stub
}
...
}