title: How can I set each character to a different color/background color in a JTextPane?
body: <p>I've been searching for this for a while and so far all I've been able to come up with is how to create a style and apply it to a character like so:</p>
  
  <pre><code>StyledDocument doc = (StyledDocument) new DefaultStyledDocument();
  JTextPane textpane = new JTextPane(doc);
  textpane.setText("Test");
  javax.swing.text.Style style = textpane.addStyle("Red", null);
  StyleConstants.setForeground(style, Color.RED);
  doc.setCharacterAttributes(0, 1, textpane.getStyle("Red"), true); 
  </code></pre>
  
  <p>This is useful if you have only a few styles in your document and want to store them by name so that you can apply them easily later on. In my application I want to be able to set the foreground color (one of only a few values) and the background color (grayscale, many different values) independently for every character in the text. It seems like a huge waste to create potentially hundreds/thousands of different styles for this. Is there a way to set these attributes without having to create a new style each time? It would be much easier if I only had to render the text but I also need to make it editable as well. Is there a way to do this with <code>JTextPane</code>, or is there another swing class that offers this functionality?</p>