Originally posted by Abhijeet Vaidya:
I want to perform some action in editor of a JFormattedTextField. So I have added "Tab" and "Enter" in the input map and specified actionMap for it.
ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), AppConstants.CHECK);
ftf.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), AppConstants.CHECK);
I'm not sure the TAB will work, because I think the focus-handling code grabs the tab before the component gets it. I haven't tried it recently, though, so perhaps I'm wrong.
The ENTER will work, but this will clobber the existing entry ("notify-field-accept") in the InputMap. This means that ftf.addActionCommand(...), which is the normal way to get the field to do something when the user hits the enter key, will no longer work.
As for mouse clicks, the InputMap/ActionMap will not involved.
You haven't said exactly what you are trying to do, but wouldn't it be easier to customize the field's Editor than to put listeners on the field itself?