Topic: 如何实现在树的节点上点击右键出现右键菜单

  Print this page

1.如何实现在树的节点上点击右键出现右键菜单 Copy to clipboard
Posted by: yangjinfeng
Posted on: 2004-08-26 09:08

如何实现在树的节点上点击右键出现右键菜单,该节点被选中,且菜单内容与节点信息相关。

2.Re:如何实现在树的节点上点击右键出现右键菜单 [Re: yangjinfeng] Copy to clipboard
Posted by: kam
Posted on: 2004-08-26 11:07

use addTreeSelectionListener, and then implements the valueChanged()

then you can do what you want ^.^

3.Re:如何实现在树的节点上点击右键出现右键菜单 [Re: yangjinfeng] Copy to clipboard
Posted by: yangjinfeng
Posted on: 2004-08-26 16:56

能提供相关的实例代码吗,谢谢

4.Re:如何实现在树的节点上点击右键出现右键菜单 [Re: yangjinfeng] Copy to clipboard
Posted by: yangjinfeng
Posted on: 2004-08-26 17:26

kam ,你说的是左键点击选择触发的事件,是我理解错了吗?我问的是击右键出现右键菜单,请明示

5.Re:如何实现在树的节点上点击右键出现右键菜单 [Re: yangjinfeng] Copy to clipboard
Posted by: kam
Posted on: 2004-08-26 18:31

when you catch the value changed, then just pop up a specific menu ^.^

If you need code, then i think you need to wait until SAT or SUN, coz i don't think i have enough time now to write an example ...

maybe you try it first, i try to write it as soon as possible ^.^

6.Re:如何实现在树的节点上点击右键出现右键菜单 [Re: yangjinfeng] Copy to clipboard
Posted by: kam
Posted on: 2004-08-27 10:43


private JPopupMenu ppmGroup = new JPopupMenu();
private JMenuItem mnuNewGroup = new JMenuItem();
private JMenuItem mnuEditGroup = new JMenuItem();
private JMenuItem mnuDeleteGroup = new JMenuItem();


declare a Pop Up Menu, 以便我們可以彈出來...

menu 入面的action 自行寫啦...^.^


private void nodeAction()
{
jTree.addTreeSelectionListener(new TreeSelectionListener(){
public void valueChanged(TreeSelectionEvent e)
{
DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)jTree.getLastSelectedPathComponent();
if (selectedNode == null)
return;
else
ppmGroup.show(); //把menu 彈出來.............
}
}
);
}


這樣就ok啦....細節我就不多打了...^.^


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923