Vote count:
0
This piece of code works fyn. But if I remove EventQueue.invokeLater() , first key that has been typed is not getting recoganised
public static class ListenerDemo implements KeyListener
{
String userString = null;
private String getUserTypedString(KeyEvent e)
{
return ((JTextField) e.getSource()).getText();
}
@Override
public void keyTyped(final KeyEvent e) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
userString = ((JTextField) e.getSource()).getText();
System.out.println("User str = " +userString);
}
});
}
Input in JCombox : 1 , In keyTyped output is User str = 1
But, If I dont use EventQueue.invokeLater()
Input in Jcombobox which I type is 1 , but output is userTyped =
Then on typing 2, I get output as userTyped = 1
If all the events are handled by EDT thread , then is it mandatory to use EventQueue.invokeLater() . Why keyType is getting recoganised late?
asked 2 mins ago
First UserTypedString is not getting recoganised in keyTyped (keyListener) without EventQueue's invokeLater
Aucun commentaire:
Enregistrer un commentaire