Originally posted by Balasubramanian Chandrasekaran:
Is there a restriction that we can add component only once. Can anyone explain me this behaviour
Yes, there is exactly this restriction. If you try to add a Component
to a second Container, it will automatically be removed from the first
Container first. There are good reasons for this, but they are easiest
to understand if you think of text fields and buttons instead of menu
items. Menu items do behave the same as other Components, though.
One thing you can try is instead of attempting to add a JMenuItem multiple
places, instead add an
Action to them. An Action isn't a Component, but
can be added directly to a JMenu (in which case a JMenuItem is
created
for you behind the scenes).
I just tried one more implementation in which i tried to add same menuitem on different menu but in that one also i am able to view menuitem on the second menu only
Code which i tried for that implementation is
But you're still adding menuItem to two different Containers. It should
appear correctly if you just do:
If you want to take my Action suggestion it would look something like:
[ April 17, 2008: Message edited by: Brian Cole ]