问题描述
我是一个经验丰富的Java程序员,但是Swing新手,请耐心等待。我想要一个JPopupWindow,它具有键盘焦点。我想回应箭头键,转义(关闭菜单)和回车(调用项目)。我必须将一个KeyListener添加到菜单中,并自己对所有这些代码进行编码,或者是否可以设置某种模式来激活这种看起来应该是标准的行为。
JPopupMenus标准Swing教程部分只提供助记符和加速器。我不特别想要那些。
难以置信的是,这完全是违反了JPopupMenu。
什么是最好的办法像我想实现的一样?
一旦你做了 jpopupMenu.show(组件调用者,int x,int y)
它会自动响应键盘,只要你想。如果这不起作用,那么你可能需要解决一些其他问题,即一些其他组件正在从菜单中抢走焦点,当它不应该等。
I am an experienced Java programmer, but a Swing newbie so please bear with me.
I wish to have a JPopupWindow which has keyboard focus. I want to respond to arrow keys, escape (to close the menu) and Enter (to invoke the item). Must I add a KeyListener to the menu and code all this myself, or is there some sort of "mode" I can set to activate this behavior which seems like it ought to be standard.
The standard Swing tutorial section on JPopupMenus speaks only of mnemonics and accelerators. I don't particularly want those.
Hard to believe that this is totally against the grain of JPopupMenu.
What is best way to get something like I want implemented?
Once you do jpopupMenu.show(Component invoker, int x, int y)
it will automatically respond to keyboard as you want. If this is not working then you might need to fix some other issue i.e some other component is snatching away focus from the menu when it should not etc.
这篇关于如何专注于JPopupMenu的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!