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?

有帮助吗?

解决方案 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:

其他提示

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()

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top