• SWT的对话框们


    对话框,都继承自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值。

    示例:

    MessageBox messageBox = new MessageBox(shell, SWT.ICON_QUESTION |SWT.YES | SWT.NO);
    messageBox.setMessage(”Is this question simple?”);
    int rc = messageBox.open();

    2、ColorDialog,选择颜色对话框

    ColorDialog dlg = new ColorDialog(shell);
    RGB rgb = dlg.open();
    if (rgb != null) {
    Color color = new Color(shell.getDisplay(), rgb);
    }

    3、DirectoryDialog,文件夹选择对话框

    DirectoryDialog dlg = new DirectoryDialog(shell);
    dlg.setFilterPath(text.getText());
    dlg.setText(”SWT’s DirectoryDialog”);
    dlg.setMessage(”Select a directory”);
    String selectedDirectory = dlg.open();

    4、FileDialog,文件选择对话框

    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()

    5、FontDial

  • 相关阅读:
    质量属性的六个常见属性场景——以《淘宝网》为例
    软件架构师如何工作——架构漫谈读后感
    机器学习——决策树
    使用八股搭建手写数据集神经网络
    大三寒假学习进度笔记(三十)
    大三寒假学习进度笔记(二十九)
    大三寒假学习进度笔记(二十八)
    大三寒假学习进度笔记(二十七)—— 强化学习
    含e最多的单词
    数据挖掘复习1
  • 原文地址:https://www.cnblogs.com/wangjiyuan/p/duihuakuang.html
Copyright © 2020-2023  润新知