Hi,

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......

Recommended Answers

All 2 Replies

Have a look at the KeyListener interface in the API doc - it allows you to respond to individual keys being pressed and/or released.

just about JPopupMenu

I'm not sure if is posible invoke JPopupMenu (rightMouseClick) with KeyBindings,

if is posible (excluding JTable) i'd prefered JDialog with JButtons,

well I tried lots of hack for JPopumMenu, but each has problem with Concurency on EDT

if you want to add JPopupMenu correctly, then add its listener to JTextPane instead of JFrame,

and create own PopupListener extends MouseAdapter, because you can pretty modify JPopupItem (dynamic contents) in

public void mouseReleased(MouseEvent e) {
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.