2013-04-18 71 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