Solved

Easy Question JTextFields

Posted on 2004-10-07
5
227 Views
Last Modified: 2010-03-31
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.
0
Comment
Question by:zaphod_beeblebrox
  • 3
  • 2
5 Comments
 
LVL 37

Accepted Solution

by:
zzynx earned 30 total points
ID: 12247629
0
 
LVL 37

Expert Comment

by:zzynx
ID: 12247635
0
 

Author Comment

by:zaphod_beeblebrox
ID: 12247651
Points well deserved zzynx!

0
 
LVL 37

Expert Comment

by:zzynx
ID: 12247689
Thanks
0
 

Author Comment

by:zaphod_beeblebrox
ID: 12249267
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!)
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now