• Post Reply Bookmark Topic Watch Topic
  • New Topic

KeyAdapter problems

 
Maksim Kogan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a JTextPane that needs to be cleared after a user hits enter. I'm using an inner class that extends KeyAdapter, however when i try to implement the method KeyTyped or KeyReleased, the JTextPane is unresponsive, if however I use KeyPressed the method is invoke, but that is not good enough as KeyPressed makes the 'enter' echo after method invocation thereby leaving a trailing newline in the JTextPane. Please Help... stuck on this for quite some time.
 
Maksim Kogan
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys, in case anybody runs into this problem here's what I did. Instead of extending KeyAapter I implemented KeyListener. Since I only needed either KeyTyped or KeyReleased to work, (either one grants the functionality I require) I defined KeyReleased and just defined KeyPressed and KeyTyped with empty bodies. Now everything works more or less smoothly, when I tried doing the same but defining KeyTyped instead it didn't work. I say it works more or less smoothly, because due to the slow speed of the response of KeyReleased, after pressing enter I can (if I do it fast enough) still type a couple of characters more before KeyListener does its thing and then the two lines get transmitted instead of 1.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!