Hi. My problem i guess it is simple but i guess I'm simple as well :). The problem is the flowing: I have a JTextFead and a search method for IDs. The IDs are 7 char long. I want to be able when the user enters 7 chars the search method to be invoked. My first idea was a focus listener and a if statement if the chars are 7 then search, but that requires the txf to lose focus and on the regain then it searches. My other idea was to detect key events but niter is a good idea I guess =/.

Hi. My problem i guess it is simple but i guess I'm simple as well :). The problem is the flowing: I have a JTextFead and a search method for IDs. The IDs are 7 char long. I want to be able when the user enters 7 chars the search method to be invoked. My first idea was a focus listener and a if statement if the chars are 7 then search, but that requires the txf to lose focus and on the regain then it searches. My other idea was to detect key events but niter is a good idea I guess =/.

Hello,

Key event will work fine from my point of view.

On every key event you can check if the length of value in JTextField is equal to 7.

Example :

if(jTextBoxObj.getText().length() == 7){
     doSearch();
}

Regards,

Hmmm ok tnx :). I just thought there is some smarter way of doing it but I guess it is ok as long as it works. Tnx again.

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.