kooyee ‘s blog

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

          [SWT] swt中右鍵菜單

          Posted on 2007-07-20 21:24 kooyee 閱讀(1821) 評論(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();
          }

          主站蜘蛛池模板: 海安县| 城市| 买车| 柳林县| 井陉县| 正宁县| 新干县| 通江县| 山西省| 冀州市| 黄浦区| 启东市| 泰安市| 崇明县| 灌南县| 迁西县| 板桥市| 达日县| 临武县| 龙游县| 交城县| 共和县| 文成县| 油尖旺区| 吉木萨尔县| 筠连县| 临沭县| 漾濞| 兰考县| 江孜县| 寿宁县| 海晏县| 理塘县| 榆社县| 明光市| 田东县| 耿马| 肥乡县| 平罗县| 太保市| 银川市|