java - deleting menu items remotely -


consider following code:

            mntmprofilesdelete.get(index).addactionlistener(new actionlistener(){             @override             public void actionperformed(actionevent e) {                     jmenuitem emntm = (jmenuitem) e.getsource();                     string text = emntm.gettext();                     component[] mns = mndelete.getparent().getcomponents();                     for(component mn : mns)                     {                         system.err.println((string)(((jmenu)mn).gettext()));                         if(mn instanceof jmenu && ((jmenu)mn).gettext().tolowercase().equals("open"))                         {                             system.err.println((string)(((jmenu)mn).gettext()));                             component[] mntms = ((jmenu) mn).getcomponents();                             for(component mntm : mntms)                             {                                 system.err.println((string)(((jmenu)mn).gettext())+"\n"+(string)(((jmenuitem)mntm).gettext()));                                 if(mntm instanceof jmenuitem && ((jmenuitem)mntm).gettext().tolowercase().equals(text.tolowercase()))                                 {                                     system.err.println((string)(((jmenu)mn).gettext())+"\n"+(string)(((jmenuitem)mntm).gettext()));                                     ((jmenu)mn).remove((jmenuitem)mntm);                                 }                             }                         }                     }                     mndelete.remove(emntm);                 }             } 

which i'm using delete 2 menu items, below:

(jmenu)father     (jmenu)open         (jmenuitem)item1         (jmenuitem)item2         etc     (jmenu)delete         (jmenuitem)item1         (jmenuitem)item2         etc 

the action listener attached -item1- below -delete-

for reason -item1- below -open- doesn't removed using above code. can't seem understand why.

many thanks.

jmenu's remove(component c) javadoc says: "removes component c menu."

afaic interpret looking @ last line of code (my weekend mind refused dig through casting galore[1] ;-) , explanation: this menu mndelete /father/delete. item you're trying remove (/father/open/item1) not in this menu.

[1] why heck casting public string gettext() (string)?


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -