通过键盘触发弹出菜单 [英] Pop menu triggering through key board

查看:64
本文介绍了通过键盘触发弹出菜单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在尝试使用JTextpane创建一个编辑器.现在,我需要在按Ctrl +空格的同时显示一个动态弹出菜单.但是问题是我只能通过右键单击才能触发弹出菜单.我使用的代码段如下所示.

Hi all,

I am trying to create an editor using JTextpane. Now I need to show a dynamic pop up menu while pressing Ctrl + space. But the problem is that I can trigger the pop up menu only by right click of mouse. The code snippet that I used is given below.

frame.addMouseListener(new MouseAdapter(){
                    public void mouseReleased(MouseEvent Me){
                      if(Me.isPopupTrigger()){
                        Pmenu.show(Me.getComponent(), Me.getX(), Me.getY());
                      }
                    }
                  });


我可以调用Ctrl +空格.但是无法使用this调用弹出菜单.是否有任何方法或快捷方式可使用键盘触发弹出菜单?请帮忙...
在此先感谢...


I am able to invoke Ctrl + space.. But not able to invoke pop up menu using this.Is there any method or short cut to trigger pop up menu using key board? Please help...
Thanks in advance......

推荐答案

听一下按键,然后采取措施.我认为这应该有效:

Listen for the key press and take action thereafter. I think this should work:

frame.addKeyListener(new java.awt.event.KeyAdapter() {
    public void keyPressed(java.awt.event.KeyEvent evt) {
        if (evt.isControlDown() &&
                evt.getKeyCode() == java.awt.event.KeyEvent.VK_SPACE) {
            Pmenu.show(this, this.getX(), this.getY());
        }
    }
});


这篇关于通过键盘触发弹出菜单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆