JAVA - set font of selectedtext in a JEditorPane
问题 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. 回答1: 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