问题
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