Howdy, Stranger!

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

Categories

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]

Comments

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


  • Shawn CarterShawn Carter Member Posts: 0

    _____ ( http://forcoder.org ) 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.