Auto complete textbox in Java Swing

后端 未结 5 648
青春惊慌失措
青春惊慌失措 2021-01-03 02:54

Is there any good ready made Java Swing component that can be used to implement auto complete textbox?

相关标签:
5条回答
  • 2021-01-03 03:33

    Here's an example on autocompletion without a drop down selection. It will only autocomplete for you when a unique match is found. The completion is auto inserted into the text field and selected. Kind of similar as to how Safari's address field works.

    The solution could be expanded to provide a list of options, however that was not part of my requirements when doing this.

    UPDATE

    I lost the domain with the original code. It can now be accessed on github: https://github.com/sasjo/autocomplete

    0 讨论(0)
  • 2021-01-03 03:42

    There is a claim that JIDE-OSS has the feature that you are requesting. That is what this forum claims, however I have not tried it.

    0 讨论(0)
  • 2021-01-03 03:47

    I hated the idea of a third-party solution, so I was always looking a way far from it. I've settle with the JTextField and a hidden JComboBox solution when I was looking with the same idea. Lately, I found something new, and seems like nobody's looking at it as alternative solution. Doing like, textfield and a clean JPopUpMenu. . .

    https://www.geeksforgeeks.org/java-swing-jpopupmenu/

    Maybe it could help, for others at least. . .

    0 讨论(0)
  • 2021-01-03 03:52

    I had some good success by using a combo box, setting the layout manager of the combo box to be border layout and then sticking in an editable JTextField. The user edits the text field which you can add a document listener to and trigger the underlying combo box to show the dropdown showing current suggestions. You can listen to the combo box for item selections and update the JTextField with the selected item. You can open the combo box using:

    getUI().setPopupVisible(JComboBox c, boolean v)
    

    To prevent accidental opening of the combo box from clicking the edge ensure you give it a zero size empty border.

    0 讨论(0)
  • 2021-01-03 03:58

    A little dated, but with a Java Web Start File attached, which actually works: http://www.jroller.com/santhosh/date/20050620.

    0 讨论(0)
提交回复
热议问题