JAVA - set font of selectedtext in a JEditorPane

梦想的初衷 提交于 2019-12-11 01:35:08

问题


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/JTextPanesetCharacterAttributesAttributeSetattrbooleanreplace.htm



来源:https://stackoverflow.com/questions/11231086/java-set-font-of-selectedtext-in-a-jeditorpane

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!