Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

JComboBox Question

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Been looking for an example of a JComboBox that will let you sort to a value as you type in the text.

String[] text = new String[5];

text[0] = "Able";
text[1] = "Betty";
text[2] = "Sally";
text[3] = "Sharon";
text[4] = "Wentworth";

JComboBox myBox = new JComboBox(text);
myBox.setEditable(true);

As an example, what I would like it to do is; type in an s and it moves to "Sally", then when I type in an h... it moves to "Sharon".

Prodon my newbie question.... but any help. Many thanks.

Mark....
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You may have to code completely new custom ComboBoxModel to add, set and insert new values to model when ComboBoxEditor fires an ActionEvent (which your ActionListener handles) then Collections.sort(List) handles the sorting then you set the selected item which has been edited or inserted.
 
Mark O'Neal
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok.... for those interested in "one" way of doing this.... here is my first cut at it.
I think a DocumentListener may work also.......

Just a note: Still trying to get it so a "return", will pick up the currently highlighted item
in the drop down.
 
Slideshow boring ... losing consciousness ... just gonna take a quick nap on this tiny ad ...
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic