JTextPane textPane = new JTextPane(); // Set logical style Style style = textPane.addStyle(null, null); StyleConstants.setForeground(style, Color.red); textPane.setLogicalStyle(style); // paragraph is now red // Set paragraph style; removes logical style style = textPane.addStyle(null, null); StyleConstants.setUnderline(style, true); textPane.setParagraphAttributes(style, true); // paragraph is now underlined, not red // Set logical style; replaces paragraph style's parent style = textPane.addStyle(null, null); StyleConstants.setForeground(style, Color.red); textPane.setLogicalStyle(style); // paragraph is now red and underlined // Get logical style and restore it after new paragraph style Style logicalStyle = textPane.getLogicalStyle(); style = textPane.addStyle(null, null); StyleConstants.setBold(style, true); textPane.setParagraphAttributes(style, true); textPane.setLogicalStyle(logicalStyle); // paragraph is now red and bold