Example usage for javax.swing JTextPane JTextPane

List of usage examples for javax.swing JTextPane JTextPane

Introduction

In this page you can find the example usage for javax.swing JTextPane JTextPane.

Prototype

public JTextPane() 

Source Link

Document

Creates a new JTextPane.

Usage

From source file:Main.java

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

    // Set text in the range [5, 7) red
    doc.setCharacterAttributes(5, 2, textPane.getStyle("Red"), true);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextPane textPane = new JTextPane();
    Element section = textPane.getDocument().getDefaultRootElement();

    int paraCount = section.getElementCount();

    for (int i = 0; i < paraCount; i++) {
        Element e = section.getElement(i);
        int rangeStart = e.getStartOffset();
        int rangeEnd = e.getEndOffset();

        String para = textPane.getText(rangeStart, rangeEnd - rangeStart);
        System.out.println(para);
    }//from  ww w .  ja v  a 2 s . c  o m
}

From source file:Main.java

public static void main(String[] argv) {
    JTextComponent textComp = new JTextPane();
    View v = textComp.getUI().getRootView(textComp);
    walkView(v, 0);/*  www.j  a v  a  2s. c o  m*/
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextPane textPane = new JTextPane();

    Style style = textPane.addStyle(null, null);
    StyleConstants.setForeground(style, Color.red);
    textPane.setLogicalStyle(style);/*from w w  w. ja v  a 2s. com*/

    style = textPane.addStyle(null, null);
    StyleConstants.setForeground(style, Color.red);
    textPane.setLogicalStyle(style);
}

From source file:Main.java

public static void main(String[] argv) {
    // Create a text pane
    JTextPane textPane = new JTextPane();

    List list = new ArrayList();
    int pos = 400;
    int align = TabStop.ALIGN_DECIMAL;
    int leader = TabStop.LEAD_NONE;
    TabStop tstop = new TabStop(pos, align, leader);
    list.add(tstop);//from   w w w  . j a  va2 s. c  om
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    JTextPane textPane = new JTextPane();

    Style style = textPane.addStyle(null, null);
    StyleConstants.setForeground(style, Color.red);
    textPane.setLogicalStyle(style);// ww w  . j a  va  2  s .  c  om

    // Set paragraph style; removes logical style
    style = textPane.addStyle(null, null);
    StyleConstants.setUnderline(style, true);
    textPane.setParagraphAttributes(style, true);
    // paragraph is now underlined, not red
}

From source file:Main.java

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

    Style style = doc.addStyle("StyleName", null);

    StyleConstants.setBold(style, true);
    doc.insertString(doc.getLength(), "Some Text", style);
}

From source file:Main.java

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

    Style style = doc.addStyle("StyleName", null);

    StyleConstants.setItalic(style, true);

    doc.insertString(doc.getLength(), "Some Text", style);
}

From source file:Main.java

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

    Style style = doc.addStyle("StyleName", null);

    StyleConstants.setFontFamily(style, "SansSerif");

    // Append to document
    doc.insertString(doc.getLength(), "Some Text", style);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    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.setFontSize(style, 30);

    doc.insertString(doc.getLength(), "Some Text", style);
}