我正在使用 aJTextPane
来打印聊天消息,实现:
private HTMLEditorKit kit;
private HTMLDocument doc;
ta = new JTextPane();
ta.setEditable(false);
ta.setContentType("text/html");
sbrText = new JScrollPane(ta);
sbrText.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
sbrText.setBorder(null);
doc = (HTMLDocument)ta.getDocument();
kit = (HTMLEditorKit)ta.getEditorKit();
消息是这样插入的:
try {
kit.insertHTML(doc, doc.getLength(), "<div style=\"padding-top:10px;
padding-bottom:10px;\" id=\"X\">" + "<div>" + from + " at
" + tid + ":</div>" + "<div style=\"padding-top:4px;" +
align + "\">" + msg + "</div>" + "</div>", 0, 0, null);
} catch (BadLocationException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
}
每条消息(div)都有一个唯一的 ID,我想选择一个特定的 ID 并更新该 html 插入的内容。
这可能吗?