如何在 JPanel CTRL+m 中按下 keyPressed?
我正在尝试通过文本编辑器组件实现 JPopupMenu 。应通过 CTRL+m 激活它。我可以在里面做吗
@Override
public void keyPressed(KeyEvent arg0) {
}
?如果可以,怎么做?因为如果我尝试
if(arg0.isControlDown()&&arg0.getKeyChar()=='m')
它是行不通的。
I'm trying to implement a JPopupMenu over a text editor component. It should be activated on CTRL+m. Can I do that inside
@Override
public void keyPressed(KeyEvent arg0) {
}
and if yes, how? Because if I try
if(arg0.isControlDown()&&arg0.getKeyChar()=='m')
it doesn't work.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
起初我认为这与 CTRL+M 与回车/换行相同有关,但事实并非如此。尝试:
我也无法使用带有 e.getKeyChar() 的字符来使其工作,但 getKeyCode() 对我有用。太棒了,它有效。但我是那种必须知道原因的人。所以我发现 这个:
At first I thought it was something to do with CTRL+M being the same thing as a carriage-return/line feed, but that wasn't true. Try:
I couldn't get it to work using chars with e.getKeyChar() either, but the getKeyCode() works for me. Great, it works. But I'm the type that has to know why. So I found this: