如何从JTextPane获取文本颜色?

时间:2018-11-12 12:25:07

标签: java swing jtextpane

我正在创建一个简单的RTF编辑器,我正在使用JTextPane组件和RTFEditorKit。我想获取在JTextPane中输入的文本的颜色。如何获得文字颜色?

1 个答案:

答案 0 :(得分:2)

使用getCharacterAttributes()

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