[英]Java: JMenuItem not working with ActionMap/AbstractAction
Generic code... 通用代码......
For some reason my JMenuItem
is not performing actions. 出于某种原因,我的
JMenuItem
没有执行操作。
I made a frame, a JMenuBar
and a JMenuItem
, everything is where it should be. 我制作了一个框架,一个
JMenuBar
和一个JMenuItem
,一切都应该是它。 I can click the JMenuItem
just fine, it highlights and closes the menu properly but no action is performed. 我可以很好地点击
JMenuItem
,它会正确地突出显示并关闭菜单但不执行任何操作。
I added a key to the ActionMap
with the JMenuItem
s name. 我使用
JMenuItem
的名称为ActionMap
添加了一个键。 I also added a key to the Input map with the exact same name and it fires fine. 我还在输入映射中添加了一个具有完全相同名称的键,它可以正常启动。
'menuitem'.setActionMap(getActionMap());
System.out.println('menuitemname'.getActionMap().size());
System.out.println('menuitemname'.getActionCommand());
returns 1 and the correct action key, respectively. 分别返回1和正确的操作键。 Clicking the menu item does nothing.
单击菜单项不会执行任何操作。 Is there something I'm missing?
有什么我想念的吗?
您可能正在寻找setAction()
方法(也可能是setActionCommand()
)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.