import javax.swing.*;
import javax.swing.text.*;
import java.awt.*;
public class MyFrame extends JFrame{
JTextPane tp;
public MyFrame () {
tp = new JTextPane();
tp.setText("Hallo Welt");
StyledDocument doc = tp.getStyledDocument();
Style style = tp.addStyle("rot", null);
StyleConstants.setForeground(style, new Color(255,0,0));
doc.setCharacterAttributes(0, 5, tp.getStyle("rot"), true);
(this.getContentPane()).add(tp);
this.pack();
this.setVisible(true);
}
public static void MyFrame String[] args) {
MyFrame f = new MyFrame ();
}
}