Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't share JMenu between JMenuBar and JPopupMenu




On Aug 20, 2006, at 4:22 PM, email@hidden wrote:

[ I originally wasn't going to post to this list because I didn't think this issue to be Mac-specific, but upon searching Sun's Forums on this issue and not finding it addressed, I am now wondering if this might just be a Mac-specific bug.]

I have menus in my component that I would like to be accessible via the JMenuBar and a JPopupMenu.  The problem is that I can't use just 1 instance of the menu and pass it to the menubar and popup; I have create 2 instances, adding the 1st to the menubar and 2nd to the popup.

Here's what I am trying:
    JMenuBar mb = new JMenuBar();
    JPopupMenu pum = new JPopupMenu();
    JMenu jm = new JMenu("Stuff");
        ... add menu items to jm
    mb.add(jm);
    pum.add(pum);

However, the above code leads to only pum showing the "Stuff" menu.

Is this a bug (OSX 10.2.8, Java 1.4)?


No, this is a misconception on how JMenuItems work. From the "How to use Menus" tutorial on Sun's website:

Note: Menu items, like other components, can be in at most one container. If you try to add a menu item to a second menu, the menu item will be removed from the first menu before being added to the second. For a way of implementing multiple components that do the same thing, see How to Use Actions.

Rick
--
Rick Genter



 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Java-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/java-dev/email@hidden

This email sent to email@hidden

References: 
 >Can't share JMenu between JMenuBar and JPopupMenu (From: email@hidden)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.