简体   繁体   English

如何从JTextPane获取文本颜色?

[英]How to get text color from JTextPane?

I am creating a simple RTF editor, I am using JTextPane component and RTFEditorKit. 我正在创建一个简单的RTF编辑器,正在使用JTextPane组件和RTFEditorKit。 I want to get the color of the text entered in JTextPane. 我想获取在JTextPane中输入的文本的颜色。 How can I get the text color? 如何获得文字颜色?

Use getCharacterAttributes() : 使用getCharacterAttributes()

AttributeSet attr = textPane.getCharacterAttributes();
Color color = (attr != null ? StyleConstants.getForeground(attr) : null);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM