Click here to Skip to main content
15,902,764 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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());
                      }
                    }
                  });

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......
Posted
Updated 21-Mar-11 2:54am
v2

1 solution

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

Java
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());
        }
    }
});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900