get parent-JMenu from JMenuItem

Hi everybody.

Is there any way to get the parent JMenu from an JMenuItem added to it? I tried getParent(), but this only returned a JPopupMenu, which is of no need for me (as far as I can see).

I get the JMenuItem from the an actionPerformed-method.

[size=1][Blue]For our true nature is sin
[B]Cradle of Filth[/b]

Comments

  • Ok, I already found a way:

    [code]
    JMenuItem menuItem = (JMenuItem) e.getSource(); // ActionEvent e
    JPopupMenu popUp = (JPopupMenu) menuItem.getParent();
    JMenu menu = (JMenu) popUp.getInvoker();
    [/code]

    If anyone knows a better way doing that, I'd appreciate it, but for now I will use this :-).


    [size=1][Blue]For our true nature is sin
    [B]Cradle of Filth[/b]


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion