2013-04-18 69 views
0

我做使用JTextPane,我需要的颜色添加一些话,但我希望有一个文本编辑器,如果在已上色的区域,用户点击与颜色(段落样式画),而不是逻辑风格。我正在寻找getParagraphAttributes,但我无法将段落样式作为属性。获取段落样式中的JTextPane

如何获得段落样式在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

为了更好地帮助越早,张贴[SSCCE(http://sscce.org/)。 – 2013-04-18 05:06:44

+0

私人风格的getColor(字符串令牌){ 如果(token.equals( “外衣”)) 回报editor.getStyle( “蓝”); return editor.getLogicalStyle(); //在这一点上,我希望当前不合逻辑的,如果可能的话。 } – 2013-04-18 22:12:40

+0

我不能编辑我的问题,所以这是我能告诉你的SSCCE的唯一途径。 – 2013-04-18 22:14:26

回答

2

尝试使用

((StyledDocument)textPane.getDocument()).getParagraphElement(position).getAttributes(); 
+0

我真的不知道如何使用您的代码获取样式属性。 (我怀疑我必须使用getAttribute(Object key)方法,但我关心的是使用什么键)。 – 2013-04-18 22:03:15

+0

只需检查所有属性名称/值 – StanislavL 2013-04-19 05:19:20