问题描述
我的应用程序的主JFrame包含一个JTextPane.当它具有焦点时,它将使用所有键盘快捷键(加速器"),而不是将其传递给JFrame的JMenu.这意味着尽管它具有焦点,例如"New Document"的ctrl-n不起作用.
My application's main JFrame contains a JTextPane. While it has focus, it consumes all keyboard shortcuts ("accelerators") instead of passing them on to the JFrame's JMenu. This means that while it has focus, eg ctrl-n for "New Document" doesn't work.
很明显,正确处理ctrl-A/C/V/X对于全选/复制/粘贴/剪切非常有用,但是我如何说服它不要吞下其他快捷方式呢?
Obviously it's useful that it handles ctrl-A/C/V/X correctly for select all/copy/paste/cut, but how do I convince it not to swallow the other shortcuts?
推荐答案
我认为在关键侦听器功能的最后,您应该可以说...
I think at the end of your key listener functions you should be able to say...
this.getParent().dispatchEvent(originalKeyEvent);
默认情况下,一旦找到KeyListener,Java不会尝试将事件进一步冒泡.
By default, once a KeyListener is found Java does not attempt to bubble an event up any further.
这篇关于如何停止JTextPane吞咽键盘快捷键(加速器)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!