| | |
Limiting how much a user can enter
![]() |
•
•
Join Date: Sep 2008
Posts: 1,566
Reputation:
Solved Threads: 196
Personally, my first instinct would be to write a listener method that got the text, counted how many characters were there, and "refused to let more be entered" by setting the text back to whatever was previously there if the user entered too much. That would work, however, my first instinct would probably be a waste of time, because there are other available methods of doing the same with less effort and probably less code.
At this link, it describes that you should either use a JFormattedTextField (you're using a JTextField) or you should use a Document listener. It gives links to both. If you want to use a JTextField, stick with the document listener.
http://java.sun.com/docs/books/tutor...textfield.html
At this link, it describes that you should either use a JFormattedTextField (you're using a JTextField) or you should use a Document listener. It gives links to both. If you want to use a JTextField, stick with the document listener.
http://java.sun.com/docs/books/tutor...textfield.html
Last edited by BestJewSinceJC; May 21st, 2009 at 9:14 pm.
![]() |
Similar Threads
- Accepting user input (C)
- How do i test if a user enter a letter in a textbox? (Visual Basic 4 / 5 / 6)
- Creating a GUI that accepts user input help (Java)
- Access Violation (Segmentation Fault) + atol (C++)
- Need help displaying when user enters negative number? (C++)
- Problems with displaying total payroll and allowing user to quit by entering a neg. (C++)
- Setting up user name and password (ColdFusion)
- i want the user to enter an input without obligating him to press enter (C++)
Other Threads in the Java Forum
- Previous Thread: problem with indexOf() and contains()
- Next Thread: Selection Is Not Within A Valid Module
| Thread Tools | Search this Thread |
911 actionlistener addressbook android api append applet application array arrays automation binary blackberry block bluetooth character chat class client code component consumer csv database desktop developmenthelp eclipse error fractal ftp game givemetehcodez graphics gui html ide image integer j2me j2seprojects japplet java javaarraylist javac javaee javaprojects jni jpanel julia lego linked linux list loops mac map method methods mobile netbeans newbie number objects online oriented panel printf problem program programming project projects properties recursion replaydirector reporting researchinmotion rotatetext rsa scanner se server set singleton sms sort sql string swing test textfields threads time title tree tutorial-sample ubuntu update windows working






