Skip to main content

cross-pollinating javax.swing.text & java.awt.font packages

2 replies [Last post]
dhorlick
Offline
Joined: 2004-05-04
Points: 0

Is there any straight-forward way to use a javax.swing.text.StyledDocument with the classes in java.awt.font? StyledDocuments track their styles using AttributeSets, while java.awt.font classes expect an AttributedCharacterIterator.

I would like to take the content from a JTextArea and display it snugly circumscribed by a scaled ellipse. I was hoping to accomplish this using a LineBreakMeasurer inside an optimization loop.

Thanks,
Dave

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
zpm
Offline
Joined: 2003-06-16
Points: 0

It seems there's no straightforward way. Some kind of a bridge is needed to represent text data in form of a CharacterIterator.

However, javax.swing.text.Segment implements CharacterIterator. It can be extended to implement AttributedCharacterIterator. You may want to take a look at javax.swing.text.TextLayoutStrategy.AttributedSegment class for an example of how it can be done.

--
Peter

dhorlick
Offline
Joined: 2004-05-04
Points: 0

Thanks, the example was helpful.

Dave