在JTextPane中获取段落样式

时间:2013-04-18 04:49:53

标签: java swing styles jtextpane

我正在使用JTextPane做一个文本编辑器,我需要为某些单词添加颜色,但我希望如果用户点击已经着色的区域,则要使用该颜色绘制(段落样式) ,不是逻辑风格。我一直在寻找getParagraphAttributes,但我无法将Paragraph Style作为财产。

如何在JTextPane中获取段落样式?

private Style getColor(String token) { 
    if (token.equals("while")) 
        return editor.getStyle("blue"); 
    return editor.getLogicalStyle(); //At this point I want current not logical if it's Possible. 
}

1 个答案:

答案 0 :(得分:2)

尝试使用

((StyledDocument)textPane.getDocument()).getParagraphElement(position).getAttributes();
相关问题