Highlight Matches In JTextPane

The image in this post shows how the highlight matching code works with a JTextPane. But actually, the code uses a JTextComponent so either a JEditorPane, JTextArea or JTextPane will work with this code.

Type in the word that you want to find, then press the FIND button and it will highlight all words matching it. The highlight matching is case insensitive so if you want to make it case-sensitive, just remove the part of the code where toLowerCase() is called.

To use the class, just do it like this:

And here is the source code for the WordEditorSearch class.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

Your email address will not be published. Required fields are marked *