开发者

Auto complete textbox in Java Swing

Is ther开发者_如何学运维e any good ready made Java Swing component that can be used to implement auto complete textbox?


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.

Auto complete textbox in Java Swing

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


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.


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


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜