Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何在 JEditorPane 中设置字体/粗体/斜体/下划线?
我正在尝试创建一个简单的文档编辑器,但我只能弄清楚如何设置整个 JEditor/JText 窗格的字体/粗体/斜体/任何内容。
RTF 是首选,HTML 也很好。
JEditorPane.getDocument() 返回 StyledDocument 的一个实例。StyledDocument 有setCharacterAttributes () 方法来设置字体属性。
相关示例:http ://www.java2s.com/Code/JavaAPI/javax.swing/JTextPanesetCharacterAttributesAttributeSetattrbooleanreplace.htm