JTextPane: getStyledDocument() : JTextPane « javax.swing « Java by API






JTextPane: getStyledDocument()

  


import java.awt.Color;

import javax.swing.JTextPane;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

public class Main {
  public static void main(String[] argv) throws Exception {
    JTextPane textPane = new JTextPane();
    StyledDocument doc = textPane.getStyledDocument();

    // Makes text red
    Style style = textPane.addStyle("Red", null);
    StyleConstants.setForeground(style, Color.red);


  }
}

   
    
  








Related examples in the same category

1.JTextPane: getDocument()
2.JTextPane: insertComponent(Component c)
3.JTextPane: insertIcon(Icon g)
4.JTextPane: replaceSelection(String content)
5.JTextPane: setCaretPosition(int position)
6.JTextPane.setCharacterAttributes(AttributeSet attr, boolean replace)
7.JTextPane: setFont(Font font)
8.JTextPane: setLogicalStyle(Style s)
9.JTextPane: setParagraphAttributes(AttributeSet attr, boolean replace)