Hello everyone. I had a quick question. How can I go about setting constraitnts for a JTextField. I'm trying to not allow users to enter any non numeric numbers, except for dollar signs, commas and periods. Also how can I restrict a JTextField to only allowing two numbers to be entered. Like from 0-99. May someone give me an example to both please. Thanks in advance.
NycNessyness
0
Junior Poster in Training
Recommended Answers
Jump to Postset up a KeyListener to it which refuses to allow anything you don't want.
Jump to PostYou can also use a JFormattedTextField: http://java.sun.com/docs/books/tutorial/uiswing/components/formattedtextfield.html
or an InputVerifier: http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html#inputVerification.
All 8 Replies
jwenting
1,889
duckman
Team Colleague
NycNessyness
0
Junior Poster in Training
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
NycNessyness
0
Junior Poster in Training
NycNessyness
0
Junior Poster in Training
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
Ezzaral
2,714
Posting Sage
Team Colleague
Featured Poster
NycNessyness
0
Junior Poster in Training
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.