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();
          ????}

          大功告成!


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


          網站導航:
           
          主站蜘蛛池模板: 渝北区| 黎川县| 青冈县| 孟连| 平舆县| 若尔盖县| 陵川县| 台中县| 方正县| 望都县| 察哈| 平乐县| 云和县| 庆安县| 鸡西市| 彝良县| 太湖县| 拉孜县| 霍邱县| 林周县| 当涂县| 盐源县| 松桃| 三亚市| 安多县| 通道| 定南县| 开江县| 甘肃省| 稷山县| 大新县| 澄迈县| 石门县| 呼图壁县| 河北区| 陇西县| 阜康市| 汤阴县| 克山县| 札达县| 莒南县|