Win a copy of Microservices in Action this week in the Web Services forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

jTextfield problems  RSS feed

 
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
 
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 ]
 
Ranch Hand
Posts: 1780
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either of the following can help:

JFormattedTextField

DocumentFilter
 
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?
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!