import javax.swing.text.*;
public class Test extends JFrame{
private JTextPane textpane=new JTextPane();
private StyledDocument document=(StyledDocument)textpane.getDocument();
....
public Test(){
......;
setColor();
}
private void setColor(){
SimpleAttributeSet attribute=new SimpleAttributeSet();
StyleConstants.setForeground(attribute,Color.blue);
document.setCharacterAttributes(6,12,attribute,false);
StyleConstants.setForeground(attribute,Color.red);
document.setCharacterAttributes(20,10,attribute,false);
......
import javax.swing.text.*;
public class Test extends JFrame{
private JTextPane textpane=new JTextPane();
private StyledDocument document=(StyledDocument)textpane.getDocument();
....
public Test(){
......;
setColor();
......;
}
private void setColor(){
SimpleAttributeSet attribute=new SimpleAttributeSet();
StyleConstants.setForeground(attribute,Color.blue);
document.setCharacterAttributes(6,12,attribute,false);
StyleConstants.setForeground(attribute,Color.red);
document.setCharacterAttributes(20,10,attribute,false);
}
......
}