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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
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
Ranch Hand

Joined: Apr 23, 2012
Posts: 32

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: 4546
    
    5

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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: InputMap / ActionMap actions leave characters in TextArea