I have a basic text editor that can style documents (bold, underline, italicize, underline, align left/right/center, color, font size/family), and that all works great. The problem I’m having is that I want the style to set my buttons and boxes to the correct styling for where the caret is.
Say, for example, I have the string
the quick brown fox jumps over the lazy dog
When I click between the u and i in quick, I want my italicize button to be toggled on to indicate that the text where the caret is has the italicized styling.
I’m using a JTextPane to hold the text, and a StyledEditorKit for the styling.
Thanks.
I think what you are looking for, is
getCharacterAttributesmethod from the JTextPanehttp://download.oracle.com/javase/7/docs/api/javax/swing/JTextPane.html#getCharacterAttributes()