• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

JComboBox

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Say My JCombobox (editable) is created by passing Vector in its constructor.
<b>
Say Vector has Five Strings "ABCDE", "ABRTY", "BTYRE", "BTREU","RTYSD1".<b>
When user key in "A" then string "ABCDE" must automatically be visible to the user. IF user ignores the suggestion and continue to type , say "ABR" then "ABRTY" must be suggested to the user.<b>
Is there any solution. Thanks in advance.
 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is a sweet litle problem that i saw in a Developer 2.0 issue.
What you need to do is:
1) set up a sorted ComboBoxModel so that all items entered are alphabetically ordered for ease in indexing pattern matches
2) set up a document listener for the JTextField that forms the Editor component
3) listen for the updates and search for the pattern in the JTextField and fill the matching item into the field. make sure you 'select' the autocompleted text, i.e., the part of the item that you inserted after the pattern typed in, so that the next character typed in by the user as a rejection response clears it out.
4) iterate for each upadte till actionPerformed!

I'm working on developing a Component for the purpose, was just a little pressed on time and wondering what the best sort algorithm would be. When its ready, i'll try to post it here!
[ December 23, 2002: Message edited by: saager mhatre ]
 
saager mhatre
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well tushar, heres the component I promised.

Its just a refined implementation of Jason Wraxall's idea as presented in the March 2002 edition of Developer 2.0.
By the time I finished this one, I figured it would be better to port the implementation to the ComboBoxEditor interface in Swing. It's only logical to perform all edits through the editor only.
I hope this helps.
 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This works great except for the case of many entries in the combo box. In this case, when their is a match, it does not scroll to the appropriate entry in the list ( it just stays at the first 10 entries ). Does anyone know how to implement a behavior where it will cause the JcomboBox to automatically scroll to the match as the user types?

Thanks
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This thread was over 7 years old; in fact, I think this is the largest kick I've ever seen. http://faq.javaranch.com/java/DontWakeTheZombies
 
Fabio Piergentili
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just thought that if someone knows the answer to the question pertaining to the subject matter it would not matter how old the ? is. In any case, I will respect the don't wake zombie rule. I guess I am breaking it by responding......

Thanks
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic