0

I'm trying to make a JTextArea that returns the value "username". I have a database that has Username as a column, and I already did research on how to SELECT and query. The only thing is, that I wish for the JTextArea to validate username AS THEY ARE TYPING their username down, like YouTube. This is primarily to keep each person from having the same username. ("Smilese is unavailable" for example, outputed as a Jlabel as the person is typing. ) Is there any Listener of JTextArea that checks AS THE PERSON IS TYPING? Or is there any code that anyone would recommend? Anyone? So to recap:

1) I have a database with a column name 2) I know how to query and find the username in the column when necessary 3) The problem is that I don't see a JTextField property (eg Action event) that can check "if the user is busy typing", only KeyTyped, which stops the user from entering more than 1 charactor before running(taking THAT one letter as a variable and outputting). 4) Any listeners? or anything of the JTextArea that can help? Any other components (JPanel, etc) that might do the trick can be mentioned here too :)

breakstorm
  • 9
  • 1
  • 7

2 Answers2

0

Swing uses DocumentListeners for this purpose. There are two entries in the Java tutorial: How to Write a Document Listener and Listening for Changes on a Document.

You basically need to implement a DocumentListener and add it to the Document of the JTextArea / JTextField. You can then react to any changes.

Tobias
  • 7,723
  • 1
  • 27
  • 44
0
 JTextArea that returns the value "username".

I wonder why you are not using JTextField for username.

Anyways, you can simpy bind a keyListener and do the required as the keys are typed.

Here's how to do it.

Community
  • 1
  • 1
coding_idiot
  • 13,526
  • 10
  • 65
  • 116