Posted by Rob Camick on October 26, 2008
The JDK already supports a class dedicated to Text Utilities. Although you may have missed it because the class is called Utilities. The class is full of static methods to help you work with text components. Of course a few more methods would never hurt.
The RXTextUtilities class provides a few more static methods that you may find usefull, especially if you are building a simple text editor and want information for a status bar:
Although the above methods use a JTextComponent as a parameter, the methods have only been tested using a JTextArea and JTextPane with plain text. I have no idea what results you would get using a text component with HTML.
Also, the getColumnAtCaret() method only makes sense when using a Monospaced font.
Many of the methods take advantage of the Element structure used by the Document of the text component to find the required information.