• Post Reply Bookmark Topic Watch Topic
  • New Topic

Keyevent is not working properly.  RSS feed

 
Yatin Shah
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
 
Chiranjeevi Kanthraj
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().

 
Darryl Burke
Bartender
Posts: 5167
11
Java Netbeans IDE Opera
  • 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!