import java.awt.Color; import javax.swing.JTextPane; import javax.swing.text.Style; import javax.swing.text.StyleConstants; public class Main { public static void main(String[] argv) throws Exception { JTextPane textPane = new JTextPane(); Style style = textPane.addStyle(null, null); StyleConstants.setForeground(style, Color.red); textPane.setLogicalStyle(style); Style logicalStyle = textPane.getLogicalStyle(); style = textPane.addStyle(null, null); StyleConstants.setBold(style, true); textPane.setParagraphAttributes(style, true); textPane.setLogicalStyle(logicalStyle); } }