I figured out how to do styled text editing in Java with a swing JEditorPane. It's not terribly complicated, but it isn't necessarily how I would have imagined styled text support would be designed.
The weirdest part is that you represent text style information using the interface AttributeSet. I had to dig through the javax.swing.text package to find out how to create an AttributeSet that has the right attribute values, and which concrete classes to use. These turned out to be SimpleAttributeSet (which implements MutableAttributeSet) and StyleConstants, which is a helper class that has static methods like setFontFamily() that map style information into attributes.
Finally, I used the StyledDocument interface to insert text with style information by calling its insertString() method.
8:34:23 AM
|
|