Hexise's Blog

          業精于勤荒于嬉 行成于思毀于隨
          posts - 13, comments - 12, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          設置JFace的Dialog樣式

          Posted on 2006-12-29 12:53 Hexise 閱讀(1658) 評論(0)  編輯  收藏

          經常性的,自己設計的對話框無法改變大小,沒有最大化最小化按鈕,等等.在哪里設置這些屬性呢?

          JFace的Dialog繼承于Window類,該類中有一方法,設置Shell的樣式.

          setShellStyle

          protected void setShellStyle(int?newShellStyle)
          Sets the shell style bits. This method has no effect after the shell is created.

          The shell style bits are used by the framework method createShell when creating this window's shell.

          Parameters:
          newShellStyle - the new shell style bits


          在Dialog的構造函數中調用該方法,即可更改Dialog的樣式.下為一例:

          import ?org.eclipse.jface.dialogs.Dialog;
          import ?org.eclipse.swt.SWT;
          import ?org.eclipse.swt.browser.Browser;
          import ?org.eclipse.swt.layout.GridData;
          import ?org.eclipse.swt.widgets.Composite;
          import ?org.eclipse.swt.widgets.Control;
          import ?org.eclipse.swt.widgets.Shell;

          public ? class ?BrowserDialog? extends ?Dialog? {

          ????
          private ?String?url;

          ????
          public ?BrowserDialog(Shell?parent,?String?url)? {
          ????????
          super (parent);
          ????????setShellStyle(getShellStyle()?
          | ?SWT.RESIZE? | ?SWT.MAX);
          ????????
          this .url? = ?url;
          ????}


          ????
          protected ?Control?createContents(Composite?parent)? {
          ????????Browser?browser?
          = ? new ?Browser(parent,?SWT.NONE);
          ????????browser.setUrl(url);
          ????????GridData?gd?
          = ? new ?GridData(GridData.FILL_BOTH);
          ????????gd.minimumWidth?
          = ? 600 ;
          ????????gd.minimumHeight?
          = ? 400 ;
          ????????browser.setLayoutData(gd);
          ????????
          return ?browser;
          ????}

          }

          import ?org.eclipse.swt.SWT;
          import ?org.eclipse.swt.widgets.Display;
          import ?org.eclipse.swt.widgets.Shell;

          public ? class ?TestDialog? {

          ????
          public ? static ? void ?main(String[]?args)? {

          ????????
          final ?Shell?shell? = ? new ?Shell(SWT.DIALOG_TRIM? | ?SWT.RESIZE? | ?SWT.MIN? | ?SWT.MAX);
          ????????
          final ?Display?display? = ?shell.getDisplay();

          ????????String?path?
          = ? " C:/Temp/log.html " ;
          ????????BrowserDialog?dlg?
          = ? new ?BrowserDialog(shell,?path);
          ????????dlg.open();

          ????????
          while ?( ! shell.isDisposed())? {
          ????????????
          if ?( ! display.readAndDispatch())? {
          ????????????????display.sleep();
          ????????????}

          ????????}


          ????}

          }

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 合作市| 印江| 崇左市| 安陆市| 兴隆县| 崇义县| 德保县| 巫溪县| 冷水江市| 临澧县| 防城港市| 白银市| 乐清市| 凭祥市| 揭西县| 若尔盖县| 浮梁县| 黎平县| 彭水| 隆尧县| 阳信县| 资中县| 永州市| 祁门县| 正蓝旗| 福州市| 鹤庆县| 英德市| 阿尔山市| 余江县| 尼勒克县| 湟中县| 泌阳县| 建宁县| 太白县| 横峰县| 吉首市| 秦安县| 交城县| 金门县| 博客|