SWT有不同类型的对话框。有些对话框具有特殊的属性。
MessageBox messageBox = new MessageBox(shell, SWT.OK|SWT.CANCEL); if (messageBox.open() == SWT.OK) { System.out.println("Ok is pressed."); }
每个对话框的open()方法返回不同的类型。例如, MessageBox对话框从open()方法返回int类型。因此,需要编写不同的条件来处理每一个对话框的返回值。
MessageBox用于给用户回馈信息。你可以使用或(|)操作来联合不同的样式,如源代码3所示:
源代码3. MessageBox例子
MessageBox messageBox = new MessageBox(shell, SWT.OK| SWT.CANCEL| SWT.ICON_WARNING); messageBox.setMessage("www.korayguclu.de"); messageBox.open();
可用的按钮常量如下所列。使或操作可以完成不同按钮的联合。SWT框架按照style bits创建对话框。按钮常量有:
SWT.ABORT //中止
SWT.OK
SWT.CANCEL
SWT.RETRY
SWT.IGNORE //忽略
SWT.YES
SWT.NO
可用的图标有:
SWT.ICON_ERROR
SWT.ICON_INFORMATION
SWT.ICON_QUESTION
SWT.ICON_WARNING
SWT.ICON_WORKING