我正在使用可视化工具包 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) {}
}
}
});
谢谢