private void addHTML(String text) {
   HTMLDocument hdoc = (HTMLDocument) doc;
   try {
     hdoc.insertAfterEnd(hdoc.getCharacterElement(hdoc.getLength()), text);
   } catch (BadLocationException | IOException ex) {
     ex.printStackTrace();
   }
 }
 public void appendToEnd(String text) {
   Element root = document.getDefaultRootElement();
   try {
     document.insertAfterEnd(root.getElement(root.getElementCount() - 1), text);
   } catch (BadLocationException e) {
     logger.error("Insert in the HTMLDocument failed.", e);
   } catch (IOException e) {
     logger.error("Insert in the HTMLDocument failed.", e);
   }
 }