Here you can find the source of setSelectionForeground(JTextPane textPane, Color color)
public static void setSelectionForeground(JTextPane textPane, Color color)
//package com.java2s; //License from project: Apache License import java.awt.Color; import javax.swing.JTextPane; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; public class Main { /**/*from w w w. j av a 2 s . c om*/ * Sets the foreground color of the selection. */ public static void setSelectionForeground(JTextPane textPane, Color color) { if (color != null) { String FOREGROUND = "foregroundColor." + color.toString(); Style foregroundStyle = new StyleContext().addStyle(FOREGROUND, null); foregroundStyle.addAttribute(StyleConstants.Foreground, color); textPane.setCharacterAttributes(foregroundStyle, false); } } }