문제

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