• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem with KeyEvent.consume() method

 
Werner Fletcher
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is it that this method consumes everything except a "space" ? I have been pulling my hair out about this! Is there any other way that I can consume a "space"? I'm using this workaround for now, but I don't like doing this.

Thanks!
 
Werner Fletcher
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anybody?
 
Darryl Burke
Bartender
Posts: 5152
11
Java Netbeans IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use a DocumentFilter, not a KeyListener, and you won't have this problem.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15713
73
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry, I don't have an answer to your question, but in the code that you posted you are not calling ke.consume() anywhere. And can you explain a bit more about the context in which you are using this? Pressing a key leads to multiple events, for example a "key pressed" and a "key released" event. Maybe (I'm just guessing here) you handle only the "key released" event, while some other component in your program is (also) reacting to the "key pressed" event.

*edit* Ah, Darryl just posted an answer that's probably more useful than mine.
 
Werner Fletcher
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Darryl Burke wrote:Use a DocumentFilter, not a KeyListener, and you won't have this problem.


I will play with that tomorrow and give some feedback. Thanks for the info!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!