将下面这段代码加入到你的事件处理函数中即可:
new PopupDialog(button.getShell(), PopupDialog.HOVER_SHELLSTYLE,
true, false, false, false, false, null, null) {
private static final int CURSOR_SIZE = 15;
protected Point getInitialLocation(Point initialSize) { //弹出窗口的初始位置,此处为鼠标的位置
//show popup relative to cursor
Display display = getShell().getDisplay();
Point location = display.getCursorLocation();
location.x += CURSOR_SIZE;
location.y += CURSOR_SIZE;
return location;
}
protected Control createDialogArea(Composite parent) { //创建弹出窗口里的内容
Label label = new Label(parent, SWT.WRAP);
label.setText("Only for test");
label.addFocusListener(new FocusAdapter() {
public void focusLost(FocusEvent event) {
close();
}
});
// Use the compact margins employed by PopupDialog.
GridData gd = new GridData(GridData.BEGINNING
| GridData.FILL_BOTH);
gd.horizontalIndent = PopupDialog.POPUP_HORIZONTALSPACING;
gd.verticalIndent = PopupDialog.POPUP_VERTICALSPACING;
label.setLayoutData(gd);
return label;
}
}.open();//打开对话框
你可以自己设置弹出窗口的内容布局,修改里面的函数就可以了。