zaphod_beeblebrox
asked on
Easy Question JTextFields
Simple really
How do I set a JTextField, for example:
JTextField MyName = new JTextField(10);
So that when I add the TextField to a panel it accepts ONLY 10 characters and no more. When I add a TextField like this to a panel, you can type as much as you like. Is there a way of making only allow you to type in the max number of characters I specify?
I've seen reference to this on the net, but can't locate an answer.
How do I set a JTextField, for example:
JTextField MyName = new JTextField(10);
So that when I add the TextField to a panel it accepts ONLY 10 characters and no more. When I add a TextField like this to a panel, you can type as much as you like. Is there a way of making only allow you to type in the max number of characters I specify?
I've seen reference to this on the net, but can't locate an answer.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://javaalmanac.com/egs/javax.swing.text/LimitText.html
ASKER
Points well deserved zzynx!
Thanks
ASKER
Just thought I'd add the following.
The top example, quotes:
"import com.sun.java.swing.text.*; "
This will only work with older versions of Java.
If you're having problems change it to
"import javax.swing.text.*;"
and it works perfectly.
Took me a while to figure that one out...(DOH!)
The top example, quotes:
"import com.sun.java.swing.text.*;
This will only work with older versions of Java.
If you're having problems change it to
"import javax.swing.text.*;"
and it works perfectly.
Took me a while to figure that one out...(DOH!)