*
The moose likes Swing / AWT / SWT and the fly likes jTextfield problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "jTextfield problems" Watch "jTextfield problems" New topic
Author

jTextfield problems

Alex Rugav
Greenhorn

Joined: May 03, 2006
Posts: 19
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

Joined: Apr 11, 2005
Posts: 744
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

Joined: Sep 16, 2005
Posts: 1780
Either of the following can help:

JFormattedTextField

DocumentFilter


There is no emoticon for what I am feeling!
Alice B Palmer
Greenhorn

Joined: Apr 25, 2006
Posts: 25
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

Joined: Sep 16, 2005
Posts: 1780
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.
 
subject: jTextfield problems