How do I add spell checking to a JTextArea?

旧城冷巷雨未停 提交于 2019-12-22 04:38:14

问题


I have a small Java application that has a JTextArea where the user enters text. I would like to add spell checking capabilities to this component similar to the way that Microsoft Word does it, i.e. misspelled words are underlined and a popup menu with corrections is displayed when the user right clicks on the underlined word. Are there any open source libraries for adding this functionality to JTextAreas?


回答1:


You could implement your own spell checker using a dictionary (can get quite large depending on languages you support), then distance metrics are calculated from the words in the text box to the dictionary. Underlining can be done using font styling, there as applet based sample here.

Jaspell is a Java implementation of the popular Aspell. In there are some explantions of the search algorithms used.

As mentioned previously Jazzy is also great and IBM provides a nice tutorial.




回答2:


I haven't tried this before, but I came across it a little while ago: http://sourceforge.net/projects/jazzy/



来源:https://stackoverflow.com/questions/1523699/how-do-i-add-spell-checking-to-a-jtextarea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!