Here you can find the source of appendAsGreen(JTextPane pane, String fontName, int fontSize, String s)
public static void appendAsGreen(JTextPane pane, String fontName, int fontSize, String s)
//package com.java2s; //License from project: Open Source License import java.awt.Color; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; public class Main { public static final Color SUCCESSFUL_GREEN = new Color(0x3E8927); public static void appendAsGreen(JTextPane pane, String fontName, int fontSize, String s) { if (pane.getStyle("greenStyle") == null) { Style greenStyle = pane.addStyle("greenStyle", null); StyleConstants.setForeground(greenStyle, SUCCESSFUL_GREEN); StyleConstants.setFontFamily(greenStyle, fontName); StyleConstants.setFontSize(greenStyle, fontSize); }//from w ww. j a v a2s .c o m StyledDocument doc = (StyledDocument) pane.getDocument(); try { doc.insertString(doc.getLength(), s, pane.getStyle("greenStyle")); } catch (BadLocationException ex) { } } }