| | |
Key Press event Restriction
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jun 2004
Posts: 295
Reputation:
Solved Threads: 1
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:
Or something like that.
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)
void keyPressed(keyEvent e) { numberOfCharsInTextField++; if (numberOfCharsInTextField > 3) { numberOfCharsInTextField--; textField.setText(oldText); } }
Overclocking is for geeks. I'm such a geek.
![]() |
Similar Threads
- Detecting the occurrence of a key press event (Python)
- Get Key Press (Python)
- problems with key event (Visual Basic 4 / 5 / 6)
- textbox key press event (VB.NET)
- pause until any key pressed in linux (C)
Other Threads in the Java Forum
- Previous Thread: Mortgage Program help
- Next Thread: 10 line text file
Views: 7177 | Replies: 2
| Thread Tools | Search this Thread |
Tag cloud for Java
911 addball addressbook android api append apple applet application arguments array arrays automation binary bluetooth button chat class classes client code component css csv database draw eclipse ee error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer j2me java javaarraylist javaprojects jmf jni jpanel julia jvm key linux list loan loop map method methods mobile netbeans newbie number object oracle output packets phone print problem program programming project recursion reporting robot scanner screen se server service set size sms socket software sort sql stream string swing test threads time transfer tree ubuntu windows wrong





