Here you can find the source of insertStyledString(JTextPane textPane, String text, SimpleAttributeSet attrSet, Color background, Color foreground, String fontFamily, int fontSize, boolean bold, boolean italic, boolean underline, boolean strikeThrough, Boolean superscript)
public static SimpleAttributeSet insertStyledString(JTextPane textPane, String text, SimpleAttributeSet attrSet, Color background, Color foreground, String fontFamily, int fontSize, boolean bold, boolean italic, boolean underline, boolean strikeThrough, Boolean superscript)
//package com.java2s; //License from project: LGPL import java.awt.Color; import javax.swing.JTextPane; import javax.swing.text.BadLocationException; import javax.swing.text.Document; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; public class Main { public static SimpleAttributeSet insertStyledString(JTextPane textPane, String text, SimpleAttributeSet attrSet, Color background, Color foreground, String fontFamily, int fontSize, boolean bold, boolean italic, boolean underline, boolean strikeThrough, Boolean superscript) { if (attrSet == null) { attrSet = new SimpleAttributeSet(); }/*from w w w . jav a 2 s.c o m*/ if (background != null) StyleConstants.setBackground(attrSet, background); if (foreground != null) StyleConstants.setForeground(attrSet, foreground); if (fontFamily != null) StyleConstants.setFontFamily(attrSet, fontFamily); if (fontSize > 0) StyleConstants.setFontSize(attrSet, fontSize); if (bold) StyleConstants.setBold(attrSet, true); if (italic) StyleConstants.setItalic(attrSet, italic); if (underline) StyleConstants.setUnderline(attrSet, underline); if (strikeThrough) StyleConstants.setStrikeThrough(attrSet, strikeThrough); if (superscript != null) { if (superscript) { StyleConstants.setSuperscript(attrSet, true); } else { StyleConstants.setSubscript(attrSet, true); } } if (textPane != null) { Document doc = textPane.getDocument(); try { doc.insertString(doc.getLength(), text, attrSet); } catch (BadLocationException e) { e.printStackTrace(); } } return attrSet; } }