This week's book giveaway is in the Reactive Progamming forum.
We're giving away four copies of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams and have Adam Davis on-line!
See this thread for details.
Win a copy of Reactive Streams in Java: Concurrency with RxJava, Reactor, and Akka Streams this week in the Reactive Progamming forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Ganesh Patekar

Keyevent is not working properly.

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all,

I am restricting user to enter any other character to TextField. I am also restricting user to enter more than 15 character in firstName and lastName field. My code is workng for all other character other than alphabets. But, it's not working for Shift, Alt, Backspace, and Capslock key. It's counting keystrok++ rather than keystroke --. Please check my code as follow:



Is any one help me?

Thanking You,
Yatin
 
Ranch Hand
Posts: 290
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

My code is workng for all other character other than alphabets. But, it's not working for Shift, Alt, Backspace, and Capslock key


Check the if conditions for
Shift - 16
Alt - 18
Back space -8
Caps lock- 20

af.keystroke++;


is happening irrespective of key, because its the first line of the method keyPressed().

 
Bartender
Posts: 5167
11
Netbeans IDE Opera Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should be using a DocumentFilter, not a KeyListener.
 
Yatin Shah
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello All,

Thanks for your quick reply. I have userd DocumentFilter now it's working fine.

Thanking You,
Yatin
 
Evacuate the building! Here, take this tiny ad with you:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!