2

How can I set the font/bold/italic/underline whatever of some text in a JEditorPane?

I am trying to create a simple document editor, but i can only figure out how to set the font/bold/italic/whatever of the ENTIRE JEditor/JText pane.

RTF is preferred, HTML is fine as well.

Primm
  • 1,347
  • 4
  • 19
  • 32

1 Answers1

4

JEditorPane.getDocument() returns an instance of StyledDocument. StyledDocument has setCharacterAttributes() method to set the font properties.

Related example: http://www.java2s.com/Code/JavaAPI/javax.swing/JTextPanesetCharacterAttributesAttributeSetattrbooleanreplace.htm

18bytes
  • 5,951
  • 7
  • 42
  • 69