Java Swing
This example shows how to use JOrtho Spell checker with Java Swing text components.
(1) Download JOrtho library jar and a dictionary (e.g. dictionary_en_2013_03.zip) from here.
(2) Installed JOrtho jar to your local .m2 folder using:
mvn install:install-file -Dfile="D:\thirdParty\jortho.jar" -DgroupId=com.inet.jortho -DartifactId=jortho -Dversion=1.0 -Dpackaging=jar
(3) Create a simple project from your IDE or using maven-archetype-quickstart
(4) Put your dictionary file ending with extension ortho in resource folder (project-root/src/resources)
(5) Create file dictionary.cnf in resource folder (project-root/src/resources). Specify comma separated language codes (e.g. 'en')
extension=.ortho languages=en
(6) Now create Java Classes. The JOrtho code will look like this:
SpellChecker.setUserDictionaryProvider(new FileUserDictionary());
SpellChecker.registerDictionaries( JorthoExample.class.getResource("/dictionary"), "en"); SpellChecker.register(ui.getTextComponent());
SpellCheckerOptions sco=new SpellCheckerOptions(); sco.setCaseSensitive(true); sco.setSuggestionsLimitMenu(15);
JPopupMenu popup = SpellChecker.createCheckerPopup(sco); ui.getTextComponent().setComponentPopupMenu(popup);
You can also invoke a spell checker dialog instead of using JPopup menu.
SpellChecker.showSpellCheckerDialog( ui.getTextComponent(), sco );
Dependencies and Technologies Used: - com.inet.jortho:jortho 1.0: POM was created from install:install-file.
- JDK 1.8
- Maven 3.0.4
|