Hi, can anyone tell me how to make the text a user types into a JTextfield appear in uppercase regardless if caps is on or not?
Thanks
Glen..

Recommended Answers

All 4 Replies

Read the API documentation for JTextField. The introductory section has an example of exactly that.

You need to implement the KeyListener interface(or alternatively extend KeyAdapter class) in this case and by using getKeyCode() event you can retrieve the corresponding ASCII value. Then if it is in lower case add 32 to its ASCII value and display it.

Adding 32 to get upper case only works for the 26 letters of the English alphabet. Use toUpperCase(...) to convert accented characters, other languages and scripts to upper case properly.

Thanks for the input guys!
Glen

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.