*
The moose likes Swing / AWT / SWT and the fly likes Way to share JMenuItems with JMenus and JPopupMenu? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Way to share JMenuItems with JMenus and JPopupMenu?" Watch "Way to share JMenuItems with JMenus and JPopupMenu?" New topic
Author

Way to share JMenuItems with JMenus and JPopupMenu?

myron schabe
Greenhorn

Joined: Aug 21, 2002
Posts: 19
Does anyone know of a way to 'share' JMenuItems with both JMenus and JPopupMenus - for instance:
JMenuItem mniExample1 = new JMenuItem("Example 1");
JMenu mnuExample = new JMenu("Examples");
JPopupMenu pmExample = new JMenu("Examples");
mnuExample.add(mniExample1);
pmExample.add(mniExample1);
What happens when I do this is that the Example1 menuItem only shows up in the popup menu not both.
Thanks
Chantal Ackermann
Ranch Hand

Joined: Sep 28, 2000
Posts: 508
You should not share JMenu and JMenuItem instances. these are view components, and you definitely need an instance each time you want it displayed. what you can (and should) share is the listener that you attach to each menu item. or you can use the class Action (see the API)
Chantal
Daniel Searson
Ranch Hand

Joined: Dec 03, 2000
Posts: 83
Check the API documentation - there is a method in the JMenu class that spits out a JPopupMenu that is exactly like the JMenu.
Hope that helps.
 
jQuery in Action, 2nd edition
 
subject: Way to share JMenuItems with JMenus and JPopupMenu?
 
Similar Threads
JMenuItems
Adding Submenu to JMenuItem.
keep the JMenu from closing the pop up of JMenuItems
JPopupMenu JMenuItem and JMenuItem : Listen to each other?
Multiple JMenuItem layout