popup menu

I want to have a popup menu and a menu in the menubar to contain the same menu items. click on either one should launch the event.

is this valid

JMenuBar mymenubar=new JMenuBar();

JMenu mymenu=new JMenu("Tools");

JMenuItem item1=new JMenuItem("Cut");

JMenuItem item2=new JMenuItem("Copy");

JMenuItem item3=new JMenuItem("Paste");

mymenu.add(item1);

mymenu.add(item2);

mymenu.add(item3);

mymenubar.add(mymenu);

//add event handlers to these

//now, set up the JPopupMenu

JPopupMenu mypopupmenu=new JPopupMenu();

mypopupmenu.add(item1);

mypopupmenu.add(item2);

mypopupmenu.add(item3);

is this allowed or will the compiler complain?

[759 byte] By [rapte] at [2007-9-26 2:01:34]
# 1
I don't see what the compiler would have to complain about, but then I don't see your whole program. Wouldn't it be faster to just compile it and see?
DrClap at 2007-6-29 8:42:02 > top of Java-index,Archived Forums,Java Programming...
# 2
ok, it doesnt let me do that. if i add it to the menubar menu, it dissappears from the popup menu.i guess i need 2 different menus with identical text, etc. one for hte menubar and the other for the popup menu.
rapte at 2007-6-29 8:42:02 > top of Java-index,Archived Forums,Java Programming...
# 3
If you have to do this, at least use the Action concept introduced in JDK 1.3 (instead of doing addActionListener for each MenuItem you can just addAction and use the same Action for both menu items.)
schillj at 2007-6-29 8:42:02 > top of Java-index,Archived Forums,Java Programming...