public class Main{
public static void main(String[] argv){
// 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);
StyleConstants.setBackground(style, Color.blue);
// Append to document
doc.insertString(doc.getLength(), "Some Text", style);
} }
|