开发者

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

开发者 https://www.devze.com 2023-01-07 02:01 出处:网络
My application\'s main JFrame contains a JTextPane. While it has focus, it consumes al开发者_开发问答l keyboard shortcuts (\"accelerators\") instead of passing them on to the JFrame\'s JMenu. This mea

My application's main JFrame contains a JTextPane. While it has focus, it consumes al开发者_开发问答l 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?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消