// textAndColors = a list of Color objects and strings/chars // Note: This functions changes the BACKGROUND colors // (not the text, which remains black). static JTextPane coloredTextToTextPane(L textAndColors, AttributeSet defaultAttributes default null) ctex { var pane = jTextPane(); var doc = pane.getStyledDocument(); Color color = Color.white; for (O x : textAndColors) { if (x instanceof Color) color = (Color) x; else { SimpleAttributeSet set; if (defaultAttributes == null) { set = new SimpleAttributeSet; StyleConstants.setFontFamily(set, "Courier"); StyleConstants.setBold(set, true); StyleConstants.setFontSize(set, 14); } else set = new SimpleAttributeSet(defaultAttributes); StyleConstants.setBackground(set, color); doc.insertString(doc.getLength(), String.valueOf(x), set); } } ret pane; }