File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Way to share JMenuItems with JMenus and JPopupMenu?

 
myron schabe
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 508
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 83
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic