簡體   English   中英

在JTextPane中獲取段落樣式

[英]Get paragraph style in 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. 
}

嘗試使用

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM