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) { //d出窗口的初始位置,此处为鼠标的位置
//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) { //创建d出窗口里的内容
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()//打开对话框
你可以自己设置d出窗口的内容布局,修改里面的函数就可以了。
以d出最简单的MessageDialog示例:IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage()
MessageDialog.openInformation(page.getActiveEditor().getSite().getShell(), "标题", "对话框显示内容")
1、在资源面板中编辑对话框,加入各种控件,设置好控件的ID;2、右击->ClassWizard,上面即有新建类,选好基类即可,基本的头文件软件已自动添加;
3、重复第2步,不选新建类,选中第2步中新建的对话框类,对每个控件ID添加变量。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)