java - Giving JMenuItem's name to it's ActionListener -



java - Giving JMenuItem's name to it's ActionListener -

how can give jmenuitems names actionlistener attached them at?

i've got menu scheme that's handled single actionlistener, , items in menus duplicate names. isn't problem on user end, because it's obvious what; in fact, more confusing if had different names. however, @ end, want label each item uniquely.

the section creates items looks this:

string label = getlabel(forthisitem); jmenuitem item = new jmenuitem(label); item.setname(parentmenu.getname() + "_" + label); item.addactionlistener(actionlistener); parentmenu.add(item);

interrogating item afterwards (and outside scope of method) getname() gives name gave it, should, output of

public void actionperformed(actionevent ae) { string actionperformed = ae.getactioncommand(); system.out.println("actionperformed: " + actionperformed); }

is the, perchance duplicated, name user sees, specified label, not unique name gave it.

how can give right info actionlistener?

why aren't calling setactioncommand on menuitem. instead of using setname, if phone call setactioncommand, should expect when phone call getactioncommand

also, label, not lable.

java swing user-interface menu actionlistener

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -