How to add text different color on JTextPane
This will print out “BLAH BLEG” in two different colors. public class Main { public static void main(String[] args) { JTextPane textPane = new JTextPane(); StyledDocument doc = textPane.getStyledDocument(); Style style = textPane.addStyle(“I’m a Style”, null); StyleConstants.setForeground(style, Color.red); try { doc.insertString(doc.getLength(), “BLAH “,style); } catch (BadLocationException e){} StyleConstants.setForeground(style, Color.blue); try { doc.insertString(doc.getLength(), “BLEH”,style); } catch … Read more