Link to home
Start Free TrialLog in
Avatar of zaphod_beeblebrox
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.
ASKER CERTIFIED SOLUTION
Avatar of zzynx
zzynx
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of zaphod_beeblebrox
zaphod_beeblebrox

ASKER

Points well deserved zzynx!

Thanks
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!)