aspose file tools
The moose likes Swing / AWT / SWT and the fly likes InputMap / ActionMap actions leave characters in TextArea Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Reply Bookmark "InputMap / ActionMap actions leave characters in TextArea" Watch "InputMap / ActionMap actions leave characters in TextArea" New topic
Author

InputMap / ActionMap actions leave characters in TextArea

Chris Kimball
Greenhorn

Joined: Apr 23, 2012
Posts: 29

I've added a JPopupMenu to a JPanel with a TextArea in it. The popup menu is attached to the TextArea with the usual MouseListener.

To bring up the popup menu with a keystroke, I've gotten the InputMap and added a (key, action) pair to it. The key is an alt P, the action is a defined Action instance.

The software works fine in popping up the menu and closing the menu. Alas, if the focus is on the text area, alt p ALSO produces a "pi" symbol in the text area.

The Action class uses an ActionEvent that doesn't have a consume() method. What sort of action for the ActionMap should I be using so that I can consume the alt P?


Thanks,

Chris

Here's a snippet :


Darryl Burke
Bartender

Joined: May 03, 2008
Posts: 4163
    
    3

If you don't want the default action of the keystroke to affect the text area, remove that mapping from the appropriate input map of the text area.


luck, db
There are no new questions, but there may be new answers.
 
I agree. Here's the link: http://jrebel.com/download
 
subject: InputMap / ActionMap actions leave characters in TextArea
 
Similar Threads
Swing Key bindings
JTextComponent default key bindings ... big confusion!
About Keybinding
getting KeyPressed for JDialog? example?
Using ActionMap for HotKey mapping