hengheng123456789

            BlogJava :: 首頁 :: 聯系 :: 聚合  :: 管理
            297 Posts :: 68 Stories :: 144 Comments :: 0 Trackbacks
           

          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

          }

          對話框主要有以下六種:

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

          posted on 2007-09-03 15:43 哼哼 閱讀(2970) 評論(0)  編輯  收藏 所屬分類: JAVA-Eclipse
          主站蜘蛛池模板: 长垣县| 丹凤县| 乃东县| 龙泉市| 秀山| 濮阳县| 湖口县| 胶南市| 石屏县| 澄城县| 桑日县| 宁海县| 宿松县| 车致| 九龙坡区| 广东省| 皮山县| 玉环县| 营山县| 海兴县| 中牟县| 巫山县| 清水县| 凌海市| 湖北省| 观塘区| 永嘉县| 晋江市| 义马市| 莒南县| 临海市| 宝应县| 明溪县| 克山县| 绥棱县| 金塔县| 平原县| 阿尔山市| 黄龙县| 吴川市| 乌兰察布市|