Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

textfield with drop down popup

 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am looking for an approach to how implement drop down popup for JTextField.

I have a class which maps characters and its root is TreeMap<Character, TreeMap>(myComparator). You add words in it and it has method java.util.List<String> getStrings(String startsWith).

When ever any readable character is typed in textfield it updates list model and shows it in drop down popup if any words matched for the query.

It would be nice if it wont require creating a new ui class. I have looked it in JComboBox perspective and figured that, i would have to create new combo box ui class, code new BasicComboPopup doing the listeners required by ComboPopup interface and replace the JList's model, JComboBox needs to be always in editing mode, editor would be textfield which manages the visibility of ComboPopup through KeyListener, maybe mouse and focus too.

Another approach could be BasicComboPopup alike class and manage it from JTextField.

Or what you would suggest to be better approach doing this ???

I would be thankful for any advice... haven't yet started coding it...
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
seems all you need to do is something like this


add your listeners to
- change the model
- show/hide the popup
 
reply
    Bookmark Topic Watch Topic
  • New Topic