SWT DIALOG

来源:互联网 发布:煤矿系统故障模拟软件 编辑:程序博客网 时间:2024/05/08 09:39

1MessageBox,消息对话框

可定制的对话框样式包括:

标题栏:setText()

消息提示:setMessage()

消息图标类型:style属性,有:SWT.ICON_ERRORSWT.ICON_INFORMATIONSWT.ICON_QUESTIONSWT.ICON_WARNINGSWT.ICON_WORKING

按钮类型:style属性,有:SWT.OKSWT.OK | SWT.CANCELSWT.YES | SWT.NOSWT.YES | SWT.NO | SWT.CANCELSWT.RETRY | SWT.CANCELSWT.ABORT | SWT.RETRY | SWT.IGNORE

对话框返回值:int open(),返回的是点击的按钮对应的int值。

示例:

MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION |SWT.YES | SWT.NO);

messageBox.setMessage(”Is this question simple?”);

int rc = messageBox.open();

2ColorDialog,选择颜色对话框

ColorDialog dlg = new ColorDialog(shell);

RGB rgb = dlg.open();

if (rgb != null) {

Color color = new Color(shell.getDisplay(), rgb);

}

3DirectoryDialog,文件夹选择对话框

DirectoryDialog dlg = new DirectoryDialog(shell);

dlg.setFilterPath(text.getText());

dlg.setText(”SWT’s DirectoryDialog”);

dlg.setMessage(”Select a directory”);

String selectedDirectory = dlg.open();

4FileDialog,文件选择对话框

FileDialog dlg = new FileDialog(shell, SWT.OPEN);

String fileName = dlg.open();

if (fileName != null) {

// Open the file

}

对话框标题栏:void setText(String text)

文件后缀名过滤:void setFilterExtensions (String[] extensions)

缺省路径及文件名:void setFilterPath(String string)

返回值:String[] getFileNames() / String getFileName()

原创粉丝点击