title: Building up html line by line using java HTMLEditorKit insertHTML
body: <p>I am a total novice at java and programming, so to help me learn I am trying to build a trivial app that outputs some information to a logging window.</p>
  
  <p>I am outputting to a JEditorPane.  But I wanted to include hyperlinks and possibly other html stuff, so am using an HTMLEditorKit on it and calling the insertHTML(...) method.</p>
  
  <p>My issue seems to be (I think!) that I am trying to build the html code up line by line, which means leaving tags open until a later insertHTML closes them off.  But this doesn't seem to work.</p>
  
  <p>For example, the following code:</p>
  
  <pre><code>JPanel panel = new JPanel();
  getContentPane().add(panel);
  panel.setLayout(new MigLayout("", "[grow]", "[30px][grow]"));
  JEditorPane editorP = new JEditorPane();
  JScrollPane scrollPane = new JScrollPane(editorP); // put the editor pane into a scrollable pane
  panel.add(scrollPane, "cell 0 1");
  scrollPane.setPreferredSize(new Dimension(500, 500));
  scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
  editorP.setContentType("text/html");
  editorP.setEditable(false);
  HTMLDocument doc = (HTMLDocument) editorP.getDocument();
  HTMLEditorKit kit = (HTMLEditorKit) editorP.getEditorKit();
  
  try {
          kit.insertHTML(doc, doc.getLength(), "&lt;font face='calibri'&gt;", 0, 0, null);
          kit.insertHTML(doc, doc.getLength(), "www.google.com", 0, 0, null);
          kit.insertHTML(doc, doc.getLength(), "&lt;/font&gt;", 0, 0, null);
          kit.insertHTML(doc, doc.getLength(), "&lt;font face='calibri'&gt;www.yahoo.com&lt;/font&gt;", 0, 0, null);
  
          String debug = editorP.getText();
          System.out.println(debug);
  
  } catch(Exception e) { System.out.println(e); }
  </code></pre>
  
  <p>results in the html:
      
        </p>
  
  <pre><code>  &lt;/head&gt;
    &lt;body&gt;
  www.google.com
  &lt;font face="calibri"&gt;www.yahoo.com&lt;/font&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>So it seems to me (I think!) that not closing off a tags fully in the insertHTML call results in them being dropped.</p>
  
  <p>My question is: is there any way to do this line by line?  Or will I need to create my html code line by line in a string first and then pass that to insertHTML?</p>
  
  <p>All help appreciated.</p>