查看文章 SWT经验技巧2007年03月09日 星期五 下午 03:44在SWT中调用Dialog如何指定Dialog弹出时的位置?
1.
纯swt的Dialog(org.eclipse.swt.widgets.Dialog)
shell.setLocation(getInitialLocation(shell));
protected Point getInitialLocation(Shell shell)
{ int x = shell.getParent().getLocation().x+(shell.getParent().getBounds().width-shell.getSize().x)/2;
int y = shell.getParent().getLocation().y+(shell.getParent().getBounds().height-shell.getSize().y)/2;
Point location = new Point(x,y); return location; }
2.另:凡是继承自Dialog(org.eclipse.jface.dialogs.Dialog)的对话框类均可复写getInitialLocation()方法,以改变初始位置。
例:让对话框在上一shell的中间生成;
这里this.getParentShell()为IWorkbenchWindow对象。
protected Point getInitialLocation(Point initialSize)
{
int x = this.getParentShell().getLocation().x+(this.getParentShell().getBounds().width-this.getInitialSize().x)/