posts - 28, comments - 27, trackbacks - 0, articles - 0
            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理
          目的1:打開一個新的對話框時,如何設定它和父對話框的相對位置?比如在登錄對話框有一個“創建新帳號”的按鈕,用戶點擊以后,就出現新的對話框用于注冊,請問如何能讓新的對話框和舊對話框排列的整齊一些?應該是能設定二者的相對位置吧?

          最開始,以為要用Shell.setLocation來設置,但是對于一個Dialog而言,它的Shell在什么時候才能初始化呢?

          我 在構造函數里面,configureShell(Shell newShell)方法里面,Control createDialogArea(Composite parent)方法里面都調用過了this.getShell方法想得到當前的Shell,結果都拋出空指針異常....

          后來看書發現,應該重寫protected Point getInitialLocation(Point initialSize)方法

          比如,在最開始的例子中,在第二個對話框中我重寫了該方法,代碼如下:

          protected?Point?getInitialLocation(Point?initialSize)?{
          ????????Point?location?
          =?new?Point(this.getParentShell().getLocation().x
          ????????????????
          +?this.getParentShell().getBounds().width,?this
          ????????????????.getParentShell().getLocation().y
          ????????????????
          +?this.getParentShell().getBounds().height
          ????????????????
          -?this.getInitialSize().y);
          ????????
          return?location;
          ????}


          其結果就是兩個對話框底部對齊的平行排列:)

          目的2: 登陸對話框要記住上次的位置。

          想了半天,好像只能用IPreferenceStore來做了,在繼承了AbstractUIPlugin的類中放入兩個常量:

          ????public?static?final?String?LOGINDIALOG_POSITION_X?=?"LOGINDIALOG_POSITION_X";

          ????
          public?static?final?String?LOGINDIALOG_POSITION_Y?=?"LOGINDIALOG_POSITION_Y";

          然后重寫兩個方法:

          ????@Override
          ????
          protected?Point?getInitialLocation(Point?initialSize)?{

          ????????String?xposition?
          =?preferenceStore
          ????????????????.getString(Peer68TPlugin.LOGINDIALOG_POSITION_X);
          ????????String?yposition?
          =?preferenceStore
          ????????????????.getString(Peer68TPlugin.LOGINDIALOG_POSITION_Y);
          ????????
          if?(xposition?==?null?||?yposition?==?null || xposition == ""
          ??? ??? ??? ??? || yposition == ""
          )?{
          ????????????
          return?super.getInitialLocation(initialSize);
          ????????}?
          else?{
          ????????????
          return?new?Point(Integer.parseInt(xposition),?Integer
          ????????????????????.parseInt(yposition));
          ????????}
          ????}

          ????@Override
          ????
          public?boolean?close()?{
          ????????preferenceStore.setValue(Peer68TPlugin.LOGINDIALOG_POSITION_X,?
          this
          ????????????????.getShell().getLocation().x);
          ????????preferenceStore.setValue(Peer68TPlugin.LOGINDIALOG_POSITION_Y,?
          this
          ????????????????.getShell().getLocation().y);
          ????????
          return?super.close();
          ????}

          大功告成!


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


          網站導航:
           
          主站蜘蛛池模板: 武穴市| 石柱| 江川县| 盐山县| 察隅县| 阿巴嘎旗| 惠来县| 榆社县| 应城市| 青神县| 石棉县| 桂平市| 长垣县| 莱西市| 江口县| 遂川县| 乌海市| 乌兰县| 西充县| 黑龙江省| 繁峙县| 岚皋县| 余江县| 化隆| 永定县| 子长县| 邯郸县| 永城市| 察雅县| 临城县| 伊春市| 平邑县| 塔城市| 南陵县| 镇安县| 安龙县| 白玉县| 仪陇县| 绥宁县| 沭阳县| 固始县|