Tp StyledText

try {
    // Get the text pane's document
    JTextPane textPane = new JTextPane();
    StyledDocument doc = (StyledDocument)textPane.getDocument();

    // Create a style object and then set the style attributes
    Style style = doc.addStyle("StyleName", null);

    // Italic
    StyleConstants.setItalic(style, true);

    // Bold
    StyleConstants.setBold(style, true);

    // Font family
    StyleConstants.setFontFamily(style, "SansSerif");

    // Font size
    StyleConstants.setFontSize(style, 30);

    // Background color
    StyleConstants.setBackground(style, Color.blue);

    // Foreground color
    StyleConstants.setForeground(style, Color.white);

    // Append to document
    doc.insertString(doc.getLength(), "Some Text", style);
} catch (BadLocationException e) {
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.