| | |
Limiting how much a user can enter
![]() |
•
•
Join Date: Sep 2008
Posts: 1,563
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 |
android api applet application apps array arrays automation awt bidirectional binary birt bluetooth businessintelligence busy_handler(null) card chat class classes client code collision columns component constructor crashcourse database designadrawingapplicationusingjavajslider draw eclipse error errors eventlistener exception expand fractal game givemetehcodez graphics gui guidancer html ide image inetaddress integer intellij j2me java javadoc javafx javamicroeditionuseofmotionsensor javaprojects jme jni jpanel jtree julia linux list loop machine map method methods mobile mobiledevelopmentcreatejar myaggfun netbeans newbie oracle plazmic print problem program programming project radio recursion scanner server set sharepoint smart sms smsspam sort sortedmaps sql string subclass support swing textfield threads tree unlimited utility webservices windows






