I just tested the problem you described by adding keyListener to the JTextField and printing the return value of the getText () method on the console.
What I learned is that it is always one character behind if you want to use the GetText () method directly in the keyTyped or Keypressed event (I donβt know, because I usually just use the button to confirm, I m entered the text and bound KeyEvent to the Return key to launch the button if the user wants to confirm by pressing enter)
I think this is because textField updates its text value AFTER the event was shot.
I assume that this is what you have done since you did not present the sample code, so I will remove this answer if it is not.
Work on this is to implement what you want to do in the keyReleased method.
public void keyReleased(Event e) { System.out.println(myTextField.getText()); }
source share