//Search Choicelist buildConstraints(constraints, 0, 1, 2, 1, 0, 10); constraints.anchor = GridBagConstraints.CENTER; gridbag.setConstraints(searchlist, constraints); searchlist.addItem(" by First Name "); searchlist.addItem(" by Last Name "); searchlist.addItem(" by Phone Number "); searchlist.addItem(" by Street Name "); add(searchlist);
Hmmm... your code would be a lot easier to read (and thus, more likely to get useful responses from readers) if it were indented properly. Use the [ code ] tag to maintain indentation; read about it in our FAQ (see question 4). Also, we really don't need all the GUI code here - your question only relates to the search utility; that's the only part we need to see. Anyway, I eventually found that you were identifying a match using the String equals() method. The fix is simple - use equalsIngoreCase() instead. This is hardly the most efficient way to search, if the list of data is large, but it's easy enough to implement. To get wildcard capability though - that's more complex. You could implement something yourself, using String methods like startsWith() and endsWith(), but this gets complicated pretty quickly. (It might be a good idea to prohibit users from entering more than one wildcard in a string - that will reduce the complexity for you somewhat.) Note that startsWith() and endsWith() don't come with ignoreCase versions, so instead you'll probably want to convert all strings to lower case (or upper case if you prefer) before you do any searching. Alternately, it may be better or easier to find an existing regex package which contains this functionality, and incorporate it into your code. Using google I found a nice collection of related links here. Worth looking into...
"I'm not back." - Bill Harding, Twister
posted 19 years ago
jim thanks. I really appreciate it. Unfortunately I tried your link but it was really bad, barely a link that worked. I will try some more searching but I have done quite a bit and most searches dont work on just HTML and text documents only.