?
Solved

JFrame, JTextField, etc... some random questions about these things

Posted on 2005-03-06
9
Medium Priority
?
206 Views
Last Modified: 2012-05-05
Why is it that when I say:

 private JTextField firstName = new JTextField(15);

I can write over 15 characters into this textfieild.... how do I set a limit on the number of characters to be entered?
0
Comment
Question by:twibblej
[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
  • 4
  • 2
9 Comments
 
LVL 92

Accepted Solution

by:
objects earned 1000 total points
ID: 13472867
because the 15 only tells the text field how many characters wide to *display* the text filed.
To limit the number of characters entered you need to use a custom Document.

http://www.javaalmanac.com/egs/javax.swing.text/LimitText.html
0
 

Author Comment

by:twibblej
ID: 13472888
Can somebody tell me how I would go about highlighting text I put into a textfield?  Or give me a link?

Thanks
0
 
LVL 92

Expert Comment

by:objects
ID: 13472895
u could just change the fg and or bg colour of the field.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Expert Comment

by:ashok3sep
ID: 13474374
do as object says

you can change the backgraound color of the textField
0
 
LVL 5

Expert Comment

by:ashok3sep
ID: 13474384
textfield.selectAll();

and to have it done when the user moves to the field add a focus listener to the field that calls selectAll() when the field gains focus.
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

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses
Course of the Month12 days, 7 hours left to enroll

777 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