public class StyledText {
public static void main(String args[]) throws BadLocationException {
JFrame jf = new JFrame("StyledText");
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container cp = jf.getContentPane();
JTextPane pane = new JTextPane();
SimpleAttributeSet set = new SimpleAttributeSet();
StyleConstants.setBold(set, true);
// Set the attributes before adding text
pane.setCharacterAttributes(set, true);
pane.setText("Eine ");
set = new SimpleAttributeSet();
StyleConstants.setItalic(set, true);
StyleConstants.setForeground(set, Color.red);
StyleConstants.setBackground(set, Color.blue);