The issue can be reproduced using a simple program (see below):
import javax.swing.*;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.concurrent.locks.LockSupport;
public class JTextFieldWithDelayTest {
public static void main(String[] args) {
SwingUtilities.invokeLater(() -> {
JFrame frame = new JFrame();
JTextField textField = new JTextField(20);
textField.addKeyListener(new KeyAdapter() {
@Override
public void keyTyped(KeyEvent e) {
LockSupport.parkNanos(1_000_000_000L);
}
});
frame.add(textField);
frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
});
}
}
After launching the program, perform the following steps:
1) Switch to 'Spanish (United States)' input method (with 'Latin American' keyboard layout)
2) Type the following in a text field: ' ' o - i.e. single quote two times (using [ key on US keyboard) then o character.
Expected result is ''o.
Actual result is ''��.