Key Press event Restriction

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jun 2004
Posts: 1
Reputation: gandiva_skg is an unknown quantity at this point 
Solved Threads: 0
gandiva_skg gandiva_skg is offline Offline
Newbie Poster

Key Press event Restriction

 
0
  #1
Jun 16th, 2004
dear sir
Hi,

In text field I want to restrict No of character entered should be only 3 if fourth character entering in same TextFiled it should not allow.

How to solve it ?

Warm regards

sunil
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 295
Reputation: szukalski is an unknown quantity at this point 
Solved Threads: 1
szukalski szukalski is offline Offline
Posting Whiz in Training

Re: Key Press event Restriction

 
0
  #2
Jun 21st, 2004
Do you mean that the textfield should not allow a fourth char to be typed?

Or, that the String returned by getText() is rejected if over 3 chars?
Overclocking is for geeks. I'm such a geek.
Reply With Quote Quick reply to this message  
Join Date: Jun 2004
Posts: 295
Reputation: szukalski is an unknown quantity at this point 
Solved Threads: 1
szukalski szukalski is offline Offline
Posting Whiz in Training

Re: Key Press event Restriction

 
0
  #3
Jun 21st, 2004
Forgive my ignorance, I forget what the thread titles are when I'm working.
You want to restrict the textfield to only 3 chars right?
A possible solution would be to create a keyListener on the TextField and keep track of the textfield content. Do a check on keyPressed sort of like the following:
  1. void keyPressed(keyEvent e) {
  2. numberOfCharsInTextField++;
  3. if (numberOfCharsInTextField > 3) {
  4. numberOfCharsInTextField--;
  5. textField.setText(oldText);
  6. }
  7. }
Or something like that.
Overclocking is for geeks. I'm such a geek.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Java Forum


Views: 7177 | Replies: 2
Thread Tools Search this Thread



Tag cloud for Java
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC