Search code examples
javaspell-checking

Using jOrtho spell checker


How to use jOrtho spell checker? I have downloaded the latest dictionary (XML file) from wiktionary. Now how to compile it and implement it in my program?


Solution

  • I found the solution and these are the steps to add spell checking functionality. First download the jar and pre-compiled dictionary form here: http://sourceforge.net/projects/jortho/files/

    Following is the code snippet:

        SpellChecker.setUserDictionaryProvider(new FileUserDictionary());      
        SpellChecker.registerDictionaries(this.getClass().getResource("/dictionary"), "en");
        SpellChecker.register(messageWriter);
    

    Here, messageWriter is JEditor pane. Refer to documentation explanation. Put the dictionaries.cnf and dictionary_en.ortho files inside src/dictionary folder.

    You can also manipulate the pop-up menu options. Here is an example what I have done:

        SpellCheckerOptions sco=new SpellCheckerOptions();
        sco.setCaseSensitive(true);
        sco.setSuggestionsLimitMenu(10);
        JPopupMenu popup = SpellChecker.createCheckerPopup(sco);
        messageWriter.addMouseListener(new PopupListener(popup));
    

    Restricting the options to 10. See docs.