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

          }

          對話框主要有以下六種:

          1、MessageBox,消息對話框

          可定制的對話框樣式包括:

          標題欄:setText()

          消息提示:setMessage()

          消息圖標類型:style屬性,有:SWT.ICON_ERRORSWT.ICON_INFORMATION,SWT.ICON_QUESTION,SWT.ICON_WARNINGSWT.ICON_WORKING

          按鈕類型:style屬性,有:SWT.OK,SWT.OK | SWT.CANCEL,SWT.YES | SWT.NOSWT.YES | SWT.NO | SWT.CANCEL,SWT.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();

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

          posted on 2007-09-03 15:43 哼哼 閱讀(2980) 評論(0)  編輯  收藏 所屬分類: JAVA-Eclipse
          主站蜘蛛池模板: 夏津县| 高淳县| 方正县| 茶陵县| 赣榆县| 咸丰县| 司法| 新巴尔虎左旗| 宜川县| 榆中县| 温泉县| 漯河市| 卫辉市| 平远县| 卢氏县| 乌兰察布市| 巢湖市| 建平县| 勐海县| 开封市| 涿鹿县| 咸宁市| 阳信县| 杂多县| 湖北省| 平顶山市| 根河市| 吴堡县| 杭州市| 江津市| 沙河市| 阜南县| 察雅县| 荃湾区| 永丰县| 文登市| 武汉市| 陆丰市| 孟州市| 济宁市| 扬州市|