Fra*_*ick 6 java swing jtextpane
所以我创建了自己的文本窗格类(扩展JTextPane),我正在使用下面的方法向其中添加文本.但是,窗格需要可以编辑才能添加文本,但这允许用户也可以编辑窗格中的内容.
任何人都可以告诉我如何在不让用户操纵那些内容的情况下向窗格添加文本?
public void appendColor(Color c, String s) {
StyleContext sc = StyleContext.getDefaultStyleContext();
AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);
int len = getDocument().getLength();
setCaretPosition(len);
setCharacterAttributes(aset, false);
replaceSelection(s);
setCaretPosition(getDocument().getLength());
}
Run Code Online (Sandbox Code Playgroud)
直接更新文档:
StyledDocument doc = textPane.getStyledDocument();
doc.insertString("text", doc.getLength(), attributes);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13977 次 |
最近记录: |