Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Swing Component To Create AttributedStrings  RSS feed

Landon Blake
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to figure out the best way to obtain AttributedString objects from a Swing component. It seems like the Swing text components that allow you to work with styled text store their text in a StyledDocument class or something similar.

What I would really like is to find a way to obtain AttributedString object from these components. Is there a way to do this directly? How about indirectly? I took a look at the Javadoc for StyledDocument, and it appears its getText methods return plain Strings, which means I would loose the styling information.

I need AttributedString objects because I am doing custom rendering of text on a JPanel using the TextLayout class.

Thank you for any suggestions.

  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!