Please make a small, complete program that compiles, executes and shows the problem. What you posted can not be compiled and executed to show the problem.

Using key listeners can have a problem...