سؤال

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.

هل كانت مفيدة؟

المحلول

As discussed in the comments, use KEY_RELEASED rather than KEY_PRESSED.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top