Question

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?

Was it helpful?

Solution 2

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:

OTHER TIPS

You can just use setName(String name) on every JTextField you have and then you'll be able to distinguish them by calling k.getComponent().getName()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top