Sentry Spell Checker for Java |
Home Site index Contact us Catalog Shopping Cart Products Support Search |
You are here: Home > Add a spell checker to your applications > Java
Sentry Spell Checker provides everything you need to add a full spell check capability to your Java applications and applets on any platform. Click here to find out more about Sentry Spell Checker.
Click on a topic below to find out more about how Sentry Spell Checker works with your Java applications:
How to interactively spell check a JTextArea
or JTextPane component
|
Many Java applications let their users enter text via a Swing JTextArea or JTextPane component. If this is how your application works, you can add a spell checker in minutes using these simple steps:
That's all there is to it! During the spelling check, the JSpellCheckDlg object interacts with the user to check the spelling of the text. If the user corrects a misspelled word, the text is automatically updated. When the spelling check is complete, the JTextArea or JTextPane component will contain the corrected text. Any style attributes set in JTextPane (e.g., font size, bold, etc.) will be preserved when the user makes corrections. |
Many modern word processors support background (also known as "as-you-type," passive, or "on-the-fly") spell-checking, where misspelled words are highlighted by underlining with a red zigzag line. With Sentry Java SDK's BackgroundChecker class, you can add this feature in minutes:
That's it! BackgroundChecker will listen for events from the JTextArea or JTextPane component. When it detects a misspelled word, it will highlight the word with a red zigzag underline. If the user corrects the misspelled word by editing, BackgroundChecker will remove the zigzag as soon as the user's changes correct the word. If you'd like to display a popup menu when the user right-clicks over a misspelled word (on Windows; other platforms use different popup triggers), just do the following:
|
|
The text you want to spell check may not be entered by the user -- it may be read from a disk file or database, or obtained from data structures within your Java application.
Sentry Spellchecker can check words contained in Java Strings interactively or not interactively.
To check a String interactively:
Create a StringWordParser (part of the Sentry class library), and
pass the String to the constructor. The String can contain a single
word or an entire book.
Sentry will check the spelling of words in the String. If a misspelled word is found, Sentry will pop up a dialog the user can interact with to dispose of the problem. The dialog shows suggested replacements for the misspelled word. If the user makes a correction, the String will be updated automatically. Sentry can even optionally show the String's contents in a text box attached to the dialog so the user can see the misspelled words in context.
Checking strings non-interactively is done via the check method of the SpellingSession object. The check method checks the form and spelling of each word in turn, stopping when it finds a word which requires the attention of your application or it reaches the end of the string. Your Java application should call the check method in a loop; the loop terminates when the check method indicates that the end of the string has been reached. If the check method returns because it has encountered a problem with a word (e.g., a misspelling), your application should respond to the problem (e.g., by replacing the misspelled word in the string with a correctly spelled word), then continuing with the loop in which the check method is called. Your application can obtain a list of suggested replacements for the misspelled word from the Suggest function.
Copyright © 2015 Wintertree Software Inc.