• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Way to share JMenuItems with JMenus and JPopupMenu?

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 508
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 83
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Live ordinary life in an extraordinary way. Details embedded in this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic