Patrick Beard
It's like the wild west, and everybody is sheriff... - r.v.









 

 

Thursday, February 14, 2002
 

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    comment []



Click here to visit the Radio UserLand website.
Click to see the XML version of this web page.
Click here to send an email to the editor of this weblog.
© Copyright 2002 Patrick Beard .
Last update: 12/17/2002; 12:05:09 PM .
This theme is based on the SoundWaves (blue) Manila theme.
February 2002
Sun Mon Tue Wed Thu Fri Sat
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28    
Jan   Mar