How do I stop my JTextPane swallowing keyboard shortcuts (accelerators)?

不羁岁月 提交于 2019-12-11 03:05:18

问题


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.

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?


回答1:


I think at the end of your key listener functions you should be able to say...

this.getParent().dispatchEvent(originalKeyEvent);

By default, once a KeyListener is found Java does not attempt to bubble an event up any further.



来源:https://stackoverflow.com/questions/3254637/how-do-i-stop-my-jtextpane-swallowing-keyboard-shortcuts-accelerators

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!