Howdy, Stranger!

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


get parent-JMenu from JMenuItem

Feanors CurseFeanors Curse Member Posts: 70
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]


  • Feanors CurseFeanors Curse Member Posts: 70
    Ok, I already found a way:

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

    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]

  • Shawn CarterShawn Carter Member Posts: 0

    _____ ( ) free ebooks and video tutorials about { Python, C++, Assembly, Swift, Java, Scratch, MATLAB, PHP, Objective-C, Perl, Ruby, PL/SQL, Visual Basic .NET, Delphi, Go, JavaScript, Visual Basic, C#, C, R ML, SAS, LabVIEW, Crystal, Rust, Fortran, FoxPro, ABAP, F#, Transact-SQL, Julia, Kotlin, Scala, Awk, Scheme, Bash, Logo, Apex, COBOL, Lisp, Hack, D, Ada, Prolog, Alice, Lua, VBScript, Clojure, Erlang, Dart } _______

Sign In or Register to comment.