Wintertree Software Inc.

Sentry Spelling Checker Engine for Java

Home Site index Contact us Catalog Shopping Cart Products Support Search

You are here: Home > Support > Sentry Spelling Checker Engine > Java SDK > Background Checker makes text invisible when Windows Look & Feel is used


BackgroundChecker makes text invisible

Product: Sentry Spelling Checker Engine Java SDK

Version: 5.10 and later

Description: When BackgroundChecker marks a misspelled word by drawing a zig-zag line beneath it, the word's characters disappear. This happens only with JTextPane when the Windows Look and Feel is activated.

Discussion: The problem appears to be a bug in the Windows Look & Feel implementation in JDK 1.4.2.02 and later. When text is highlighted in the JTextPane, the Windows Look and Feel implementation redraws the text in the background color. Normally, this isn't a problem, because the default method of highlighting (DefaultHighlighter.DefaultHighlightPainter) is to change the background color of the highlighted text; because the background color is now different from the foreground color, the highlighted text is visible. The BackgroundChecker class, however, uses a custom HighlightPainter which does not change the background color of the highlighted text. Because the Windows Look and Feel implementation redraws the highlighted text so the foreground color is the same as the background color, the text is invisible. This problem does not occur with JTextField or JTextArea, nor does it occur when any Look and Feel other than Windows is enabled, nor does it occur in JDK 1.4.2.01. The problem can be reproduced without using BackgroundChecker by creating a custom HighlightPainter (implementation of the Swing Highlighter.HighlightPainter interface) which does not change the background color (for example, one that highlights by underlining) and using that HighlightPainter to highlight text in a JTextPane. If Windows Look and Feel is enabled, the highlighted text will be invisible.

Solution: The easiest solution is to avoid using the Windows Look and Feel until the problem is resolved. If that is not possible...

The BackgroundChecker class allows a custom HighlightPainter to be specified. Create a custom HighlightPainter class:

class MyHighlightPainter extends DefaultHighlighter.DefaultHighlightPainter {
public MyHighlightPainter(Color color) {
super(color);
}
}

Pass a new instance of the custom HighlightPainter as the third parameter to the BackgroundChecker constructor:

theBackgroundChecker = new BackgroundChecker(myTextPane, sentry,
new MyHighlightPainter(Color.red));

This change will cause BackgroundChecker to mark misspelled words by changing the background color to red. Because the background color is different from the foreground color (owing to the problem in the Windows L&F), the text will remain visible.


Home Site index Contact us Catalog Shopping Cart Products Support Search


Copyright © 2015 Wintertree Software Inc.