kooyee ‘s blog

          開源軟件, 眾人努力的結晶, 全人類的共同財富
          posts - 103, comments - 55, trackbacks - 0, articles - 66
             :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

          [SWT] swt中右鍵菜單

          Posted on 2007-07-20 21:24 kooyee 閱讀(1817) 評論(0)  編輯  收藏 所屬分類: GUI骨衣

          加入右鍵菜單到CTabFolder中的item, 同理其他的control也可以加入右鍵菜單。

          public static void main(String[] args) {
              
          final Display display = new Display();
              Shell shell 
          = new Shell(display);
              shell.setLayout(
          new FillLayout());
              
          final CTabFolder f = new CTabFolder(shell, SWT.BORDER);
              
          for (int i = 0; i < 10; i++{
                  CTabItem item 
          = new CTabItem(f, SWT.NONE);
                  item.setText(
          "item "+i);
              }

              
          final Menu menu = new Menu (shell, SWT.POP_UP);
              
          final MenuItem menuItem = new MenuItem (menu, SWT.PUSH);
              f.setMenu(menu);
              menu.addMenuListener(
          new MenuAdapter() {
                  
          public void menuShown(MenuEvent e) {
                      Point p 
          = display.getCursorLocation();
                      p 
          = f.toControl(p);
                      CTabItem item 
          = f.getItem(p);
                      
          if (item == null{
                          menu.setVisible(
          false);
                          
          return;
                     }

                     menuItem.setText(
          "action for "+item.getText());
                  }

              }
          );
              shell.setSize(
          800600);
              shell.open();
              
          while (!shell.isDisposed()) {
                  
          if (!display.readAndDispatch())
                      display.sleep();
              }

              display.dispose();
          }

          主站蜘蛛池模板: 屏山县| 杂多县| 西吉县| 肥城市| 苍溪县| 湖南省| 邳州市| 佛教| 措美县| 房山区| 巫山县| 分宜县| 肃南| 新宁县| 通州区| 三门峡市| 永济市| 奉贤区| 隆回县| 隆德县| 文水县| 遂溪县| 尼勒克县| 东乌珠穆沁旗| 台东市| 新河县| 大田县| 商丘市| 荣昌县| 高要市| 南溪县| 敦煌市| 同仁县| 木里| 于田县| 札达县| 南部县| 平原县| 巨鹿县| 平顶山市| 龙里县|