简体   繁体   English

更改AbstractAction名称

[英]Change an AbstractAction name

I have a JMenuItem bounded to an Action that I can get using item.getAction() . 我有一个JMenuItem绑定到一个Action,我可以使用item.getAction() The action name is set when constructing the Action, eg using anonymous new AbstractAction(String text, ...) . 在构造Action时设置动作名称,例如使用匿名的new AbstractAction(String text, ...) The text field is set according to a ResourceBundle and localization information. 根据ResourceBundle和本地化信息设置文本字段。 Now if I want to change localization, I would like to change the Action.NAME field so that it displays the proper localized name. 现在,如果我想更改本地化,我想更改Action.NAME字段,以便显示正确的本地化名称。 I can only get the name, eg using item.getAction().NAME but cannot change the field as it is final. 我只能获取名称,例如使用item.getAction().NAME但不能更改字段,因为它是最终的。

How could I change it's name? 我怎么能改变它的名字?

The final field is actually the key for the name property of the action. 最后一个字段实际上是操作的name属性的键。 Change the name property using putValue() 使用putValue()更改name属性

action.putValue(Action.NAME, newName);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM