Solved

Easy Question JTextFields

Posted on 2004-10-07
5
232 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
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 basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

630 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