Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

JMenuItem question

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have two menus, one is a JMenu, and one is a JPopupMenu. They both have basically the same options. I, being very naive, thought I could use one set of JMenuItems for both menus. This works fine, except when I first bring up my popup menu the items disappear from the regular menu. Could someone please explain why this happens? Is there any way to reuse my menu items in this way, or do I need to go with a set for each menu?
My code looks something like this:

Thanks
Shane
 
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without seeing more code I'm guessing that you are only creating one instance of the menu items. If this is the case then I believe they should disappear from the first menu when added to the second menu. Maybe try adding a Factory method to create specific instances of the menu items, then you will have the same menu items class but different instances. Hope that helps, not sure if I'm being clear.
-Kevin
 
Sometimes you feel like a nut. Sometimes you feel like a tiny ad.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic