title: Java Swing Storing & Rendering Text with Tabs
body: <p>My swing app contains a JEditorPane which lets users edit text in a WYSIWYG fashion, including toolbar buttons for bold, italic, and setting fonts, etc.</p>
  
  <p>The content type on the JEditorPane is text/html</p>
  
  <p>The problem: Users want to be able to type tab characters in the editor pane, close the edit dialog (saving HTML text to persistent storage) and see their tabs rendered. However, HTML treats all whitespace runs as a single space.</p>
  
  <pre><code>public class NoteTest {
      public static void main(String[] args) {
          final JEditorPane editPane1 = new JEditorPane("text/html", "Try typing some tabs");
          editPane1.setPreferredSize(new Dimension(400, 300));
          JOptionPane.showMessageDialog(null, new JScrollPane(editPane1));
          JOptionPane.showMessageDialog(null, new JScrollPane(new JEditorPane("text/html", editPane1.getText()))); // where did the tabs go?
      }
  }
  </code></pre>
  
  <p>After typing tabs in the first JEditorPane, we get the HTML text from it, and pass it to a second JEditorPane, which renders the tabs as spaces.</p>
  
  <p>How can I render these tabs? Should I be saving the user-entered content as RTF instead of HTML? Should I parse the HTML and build an HTML table with rows and cells (ugh). Or is there some way to tell swing to render the tab characters as tabs?</p>