• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 211
  • Last Modified:

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

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
twibblej
Asked:
twibblej
  • 4
  • 2
1 Solution
 
objectsCommented:
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
 
twibblejAuthor Commented:
Can somebody tell me how I would go about highlighting text I put into a textfield?  Or give me a link?

Thanks
0
 
objectsCommented:
u could just change the fg and or bg colour of the field.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
ashok3sepCommented:
do as object says

you can change the backgraound color of the textField
0
 
ashok3sepCommented:
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

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now