Solved

Easy Question JTextFields

Posted on 2004-10-07
5
228 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Unable to start eclipse ? 17 128
Requested array size exceeds VM limit 3 84
recursion example 16 111
java.io.BufferedReader   readLine()  //returns the entire file ? 4 59
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

932 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

13 Experts available now in Live!

Get 1:1 Help Now