简体   繁体   中英

Java: ArrayList with suggested phrases for an auto-complete combobox

I have a method which returns an ArrayList of phrases to be used as the user types characters into a combobox. These phrases would ideally show up in a drop-down menu.

The method is in a class of its own called PhraseList .

I have a GUI class which contains a combobox. How do I go about capturing what the user types in and then get this list of phrases to pop-up in a dropdown menu?

Sounds like you'll need to register a DocumentListener . For more information, see How to Write a Document Listener .

You can extract this/these Char(s) typed into JComboBox or JTextField, by implements Document and with AttributeSet ,

Then you can determine for continious Chars sequence (I think that only for continious), startWith Char(s), contains Char(s),

Excelent example AutoComplete JComboBox and JTextField

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM