Here you can find the source of setSelectionFontSize(JTextPane textPane, int fontSize)
public static void setSelectionFontSize(JTextPane textPane, int fontSize)
//package com.java2s; //License from project: Apache License import javax.swing.JTextPane; import javax.swing.text.Style; import javax.swing.text.StyleConstants; import javax.swing.text.StyleContext; public class Main { /**/* w w w. j av a 2s . com*/ * Sets the font size of the selected text. */ public static void setSelectionFontSize(JTextPane textPane, int fontSize) { String FONTFAMILY = "fontSize." + fontSize; Style fontSizeStyle = new StyleContext().addStyle(FONTFAMILY, null); fontSizeStyle.addAttribute(StyleConstants.FontSize, new Integer( fontSize)); textPane.setCharacterAttributes(fontSizeStyle, false); } }