As discussed in the comments, use KEY_RELEASED rather than KEY_PRESSED.
java key pressed event off by one letter
-
16-07-2023 - |
Pregunta
this is the method I'm using to test this:
private void searchFieldKeyTyped(java.awt.event.KeyEvent evt) {
String query = searchField.getText();
System.out.println(query);
}
if i type one letter though, query contains an empty string if i type another letter, query contains the single previous letter
so if i type "a", query is empty
If I type "ab", query contains "a"
If i type "abc", query contains "ab"
If I type "abcd", query contains "abc"
and so on.
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow