Here you can find the source of isSelectionBold(JTextPane textPane)
public static boolean isSelectionBold(JTextPane textPane)
//package com.java2s; //License from project: Apache License import javax.swing.JTextPane; import javax.swing.text.AttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; public class Main { /**//from ww w . jav a 2 s. c o m * Returns true if all of the selection is bold, otherwise false. */ public static boolean isSelectionBold(JTextPane textPane) { int selectionStart = textPane.getSelectionStart(); int selectionEnd = textPane.getSelectionEnd(); StyledDocument doc = (StyledDocument) (textPane.getDocument()); if (selectionStart == selectionEnd) { AttributeSet attr = textPane.getInputAttributes(); if (!attr.containsAttribute(StyleConstants.Bold, new Boolean( true))) { return false; } } else { for (int i = selectionStart; i < selectionEnd; i++) { AttributeSet attr = doc.getCharacterElement(i) .getAttributes(); if (!attr.containsAttribute(StyleConstants.Bold, new Boolean(true))) { return false; } } } return true; } }