943,737 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 8810
  • Java RSS
Jun 16th, 2004
0

Key Press event Restriction

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
gandiva_skg is offline Offline
1 posts
since Jun 2004
Jun 21st, 2004
0

Re: Key Press event Restriction

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?
Reputation Points: 21
Solved Threads: 1
Posting Whiz in Training
szukalski is offline Offline
295 posts
since Jun 2004
Jun 21st, 2004
0

Re: Key Press event Restriction

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:
Java Syntax (Toggle Plain Text)
  1. void keyPressed(keyEvent e) {
  2. numberOfCharsInTextField++;
  3. if (numberOfCharsInTextField > 3) {
  4. numberOfCharsInTextField--;
  5. textField.setText(oldText);
  6. }
  7. }
Or something like that.
Reputation Points: 21
Solved Threads: 1
Posting Whiz in Training
szukalski is offline Offline
295 posts
since Jun 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Mortgage Program help
Next Thread in Java Forum Timeline: 10 line text file





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC