java - Giving JMenuItem's name to it's ActionListener -
java - Giving JMenuItem's name to it's ActionListener -
how can give jmenuitem
s 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
Post a Comment