How to list suggestions to when typing inside the text field

前端 未结 4 1870

Hi in my Java swing application I need to show all possible existing entries with same initial characters while user typing in a text field. Lets say user type letter \'A\'

4条回答
  •  萌比男神i
    2020-12-06 04:12

    You should try JComboBox as an autosuggest box instead of JTextField. But if you still want it to be done using JTextField then...

    1. Make a JPanel containing list of suggestion.Initially it will be not visible.
    2. Whenever user types something search for it and add results to the list in JPanel.
    3. Show that JPanel at the bottom of textfield in upper layer of frame.
    4. Implement click event on list so that when ever user clicks on it the text is copied to textfield.

提交回复
热议问题