对话框,都继承自org.eclipse.swt.widgets.Dialog,有Modal的和Modeless的区分,一般的对话框处理程序如下:
<DialogType> dlg = new <DialogType>(shell);
dlg.setSomeData(data);
<ReturnType> returnValue = dlg.open();
if (returnValue == null) {
// User clicked cancel
} else {
// Do something with returnValue
}
对话框主要有以下六种:
1、MessageBox,消息对话框
可定制的对话框样式包括:
标题栏:setText()
消息提示:setMessage()
消息图标类型:style属性,有:SWT.ICON_ERROR,SWT.ICON_INFORMATION,SWT.ICON_QUESTION,SWT.ICON_WARNING,SWT.ICON_WORKING
按钮类型:style属性,有:SWT.OK,SWT.OK | SWT.CANCEL,SWT.YES | SWT.NO,SWT.YES | SWT.NO | SWT.CANCEL,SWT.RETRY | SWT.CANCEL,SWT.ABORT | SWT.RETRY | SWT.IGNORE
对话框返回值:int open(),返回的是点击的按钮对应的int值。
示例: