Here you can find the source of setStyle(JTextPane textPane, int start, int length, String name)
public static void setStyle(JTextPane textPane, int start, int length, String name)
//package com.java2s; //License from project: Open Source License import javax.swing.JTextPane; import javax.swing.text.Style; import javax.swing.text.StyleContext; import javax.swing.text.StyledDocument; public class Main { public static void setStyle(JTextPane textPane, int start, int length, String name) { StyledDocument doc = textPane.getStyledDocument(); Style style;/*from ww w . ja v a2 s. c o m*/ if (name == null) { StyleContext context = StyleContext.getDefaultStyleContext(); style = context.getStyle(StyleContext.DEFAULT_STYLE); } else style = doc.getStyle(name); doc.setCharacterAttributes(start, length, style, true); } }