Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jTextfield problems

 
Alex Rugav
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how do u set your jTextField so that it does not keep accepting input e.g for a name JTextField.how ca u also make it accept tex only and reject numerals
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not quite sure what you meant with your first question,
but to make it read-only, use .isEditable(false) on your JTextField.

If you wanted to fix the size of the field, look at the constructors in the API, just add a number to the end, eg JTextField("",10);
I think thats how it works

I'm not sure about getting it to just accept letters,
Perhaps if you have a submit button, you could get this to allow/disallow certain input in the JTextField.
[ May 12, 2006: Message edited by: colin shuker ]
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either of the following can help:

JFormattedTextField

DocumentFilter
 
Alice B Palmer
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have added a KeyListener to my JTextField and told the key listener to not accept anything that's a number. If they type a number, it beeps and deletes the number.
 
Jeff Albertson
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Alice B Palmer:
I have added a KeyListener to my JTextField and told the key listener to not accept anything that's a number. If they type a number, it beeps and deletes the number.

Does this work if you copy or cut some text (^C or ^X) and then paste (^V) it into your text field?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic