I have a JTextField to which I set an action command with the method setActionCommand(String s). It seems I can only get this action command when I use an actionPerformed event.
However I need to get some signature from my JTexteField with a keyTyped event, because I use several JTextFields, and I need to distinguish in which one the Enter key has been typed. Here is my snippet for the keyTyped event:
public void keyTyped(KeyEvent k) {
String id = k.getComponent().getClass().getSimpleName();
if (KeyEvent.VK_ENTER == k.getKeyChar() && "JTextField".equals( id )) {
JTextField tempTxt = (JTextField) k.getComponent();
// Here I would like to get my JTextField signature, such as k.getActionCommand() with actionPerformed() method
}
}
How can I do that?
However I need to get some signature from my JTexteField with a keyTyped event, because I use several JTextFields, and I need to distinguish in which one the Enter key has been typed. Here is my snippet for the keyTyped event:
use ActionListener added to JTextField instead of KeyListener
for JTextComponents
to use DocumentListener/DocumentFilter
then easiest of ways could be