Sunday, 8 September 2013

Loop over JTextPane and find certain ID

Loop over JTextPane and find certain ID

Im trying to loop over a JTextPane and find a element which has a certain
ID. I then want to be able to update the element with new text.
What i got so far:
Element root = ta.getDocument().getDefaultRootElement();
BranchElement current = (BranchElement) root.getElement(0);
if (current != null) {
Enumeration children = current.children();
while (children.hasMoreElements()) {
Element child = (Element) children.nextElement();
AttributeSet attrSet = child.getAttributes();
System.out.println(child.getAttributes());
//ImageIcon icon = (ImageIcon)
StyleConstants.getIcon(attrSet);
//System.err.println(icon.getDescription());
}
}
This is how my insert looks like:
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);
}
Any ideas how i can find my div element based on ID? And how to update it
with new text? (the div i want to update is the inner one with msg inside

No comments:

Post a Comment