嘟嘟

            BlogJava :: 首頁 :: 聯(lián)系 :: 聚合  :: 管理
            26 Posts :: 0 Stories :: 6 Comments :: 0 Trackbacks

          常用鏈接

          留言簿(6)

          我參與的團隊

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          先建一個菜單對象,處理JTree控件鼠標(biāo)事件,然后將菜單顯示出來
          JPopupMenu popup = new JPopupMenu();
          JMenuItem modify = new JMenuItem("modify");
           modify.setActionCommand("modify");
           modify.addActionListener(this);
           popup.add(modify);

          1: 左鍵選中然后再右鍵去操作
          tree.addMouseListener(new MouseAdapter() {
             public void mousePressed(MouseEvent e) {
              if (e.getButton() == e.BUTTON3) {  //BUTTON3是鼠標(biāo)右鍵
                DefaultMutableTreeNode node =  (DefaultMutableTreeNode)tree.getLastSelectedPathComponent();
                pmn.show(e.getComponent(),e.getX(),e.getY());
              }
             }
            });

          2: 直接右擊
          public void jTree1_mousePressed(MouseEvent e) {
              TreePath tp=tree.getPathForLocation(e.getX(),e.getY());
             if (tp != null) {
                    tree.setSelectionPath(tp);
                    DefaultMutableTreeNode node =  (DefaultMutableTreeNode)tp.getLastPathComponent()
             } 
             pmn.show(e.getComponent(),e.getX(),e.getY());
              }
             }
            });
          posted on 2007-05-08 03:14 fyp1210 閱讀(1493) 評論(1)  編輯  收藏 所屬分類: java basic

          Feedback

          # re: Jtree 添加右記事件[未登錄] 2009-02-18 15:05 Anna
          太謝謝了哦  回復(fù)  更多評論
            


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


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 沛县| 和平县| 西平县| 赤水市| 汤阴县| 城市| 高尔夫| 鲁山县| 三台县| 中超| 娄烦县| 吉林市| 平湖市| 夏邑县| 扶风县| 蓬溪县| 湘阴县| 屏山县| 长垣县| 凌海市| 柯坪县| 板桥市| 瑞丽市| 荥阳市| 孟连| 贵阳市| 绍兴市| 噶尔县| 宝山区| 中江县| 阳泉市| 冷水江市| 全椒县| 城口县| 达日县| 西青区| 锡林浩特市| 庆城县| 宁河县| 昌平区| 新巴尔虎右旗|