我尝试使用表单的 addmouselistener 方法并检查点击是否在标题栏区域,但鼠标侦听器不起作用。我试图在 form 和 form.getform() 和 form.getBody() 上添加鼠标侦听器,两者都不起作用。
这是我创建表单并尝试在其上添加鼠标侦听器的代码:
toolKit = new FormToolkit(parent.getDisplay());
form = toolKit.createScrolledForm(parent);
FillLayout layout = new FillLayout();
layout.type = SWT.VERTICAL;
layout.marginHeight = 10;
layout.marginWidth = 4;
canvas = new FigureCanvas(form.getBody(), SWT.DOUBLE_BUFFERED );
canvas.setViewport(new FreeformViewport());
canvas.setBackground(ColorConstants.white);
canvas.setContents(root);
form.getBody().setLayout(layout);
form.setText("Data Transactions View");
createHeaderRegion(form);
toolKit.decorateFormHeading(form.getForm());
form.getToolBarManager().add(new Action("This") { });
form.getForm().addMouseListener(new MouseListener(){
@Override
public void mouseDoubleClick(MouseEvent e) {
// TODO Auto-generated method stub
}
@Override
public void mouseDown(MouseEvent e) {
if(e.x<10 && e.y<10){
form.getToolBarManager().add(new Action("This is the toolbar") { }); // NEW LINE
form.getToolBarManager().update(true); // NEW LINE
}
}
@Override
public void mouseUp(MouseEvent e) {
// TODO Auto-generated method stub
}
}});
有什么建议么?