Example usage for javax.swing.text SimpleAttributeSet EMPTY

List of usage examples for javax.swing.text SimpleAttributeSet EMPTY

Introduction

In this page you can find the example usage for javax.swing.text SimpleAttributeSet EMPTY.

Prototype

AttributeSet EMPTY

To view the source code for javax.swing.text SimpleAttributeSet EMPTY.

Click Source Link

Document

An empty attribute set.

Usage

From source file:Main.java

public static void main(String... args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, Color.RED);
    aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");

    JTextPane tPane1 = new JTextPane();
    tPane1.setCharacterAttributes(aset, false);

    f.add(tPane1, BorderLayout.CENTER);

    f.pack();/*  w  w  w  .j  av a 2 s .c o m*/
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextPane pane = new JTextPane();
    TabStop[] tabs = new TabStop[1];
    tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE);
    TabSet tabset = new TabSet(tabs);

    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset);
    pane.setParagraphAttributes(aset, false);
    pane.setText("\tright\tleft\tcenter\tdecimal\n" + "\t1\t1\t1\t1.0\n"
            + "\t200.002\t200.002\t200.002\t200.002\n" + "\t.33\t.33\t.33\t.33\n");

    JFrame frame = new JFrame("TabExample");
    frame.setContentPane(new JScrollPane(pane));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(360, 120);/*  ww w .j  a v a  2s.  c om*/
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    JTextPane pane = new JTextPane();
    TabStop[] tabs = new TabStop[2];
    tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE);
    tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
    TabSet tabset = new TabSet(tabs);

    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset);
    pane.setParagraphAttributes(aset, false);
    pane.setText("\tright\tleft\tcenter\tValue\n" + "\t200.002\t200.002\t200.002\t200.002\n");

    JFrame d = new JFrame();
    d.setContentPane(new JScrollPane(pane));
    d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    d.setSize(360, 120);/*w ww.jav  a2  s  . c om*/
    d.setVisible(true);
}

From source file:TabExample.java

public static void main(String[] args) {

    JTextPane pane = new JTextPane();
    TabStop[] tabs = new TabStop[4];
    tabs[0] = new TabStop(60, TabStop.ALIGN_RIGHT, TabStop.LEAD_NONE);
    tabs[1] = new TabStop(100, TabStop.ALIGN_LEFT, TabStop.LEAD_NONE);
    tabs[2] = new TabStop(200, TabStop.ALIGN_CENTER, TabStop.LEAD_NONE);
    tabs[3] = new TabStop(300, TabStop.ALIGN_DECIMAL, TabStop.LEAD_NONE);
    TabSet tabset = new TabSet(tabs);

    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.TabSet, tabset);
    pane.setParagraphAttributes(aset, false);
    pane.setText("\tright\tleft\tcenter\tdecimal\n" + "\t1\t1\t1\t1.0\n"
            + "\t200.002\t200.002\t200.002\t200.002\n" + "\t.33\t.33\t.33\t.33\n");

    JFrame frame = new JFrame("TabExample");
    frame.setContentPane(new JScrollPane(pane));
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setSize(360, 120);// ww  w . j  av  a2s . c o  m
    frame.setVisible(true);
}

From source file:Main.java

private static void appendToPane(JTextPane tp, String msg, Color f, Color b) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, f);
    aset = sc.addAttribute(aset, StyleConstants.Background, b);

    aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
    aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);

    int len = tp.getDocument().getLength();
    tp.setCaretPosition(len);/*from   w  w  w  . j a v a 2s.com*/
    tp.setCharacterAttributes(aset, false);
    tp.replaceSelection(msg);
}

From source file:Main.java

public void append(Color c, String s) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    int len = getDocument().getLength();
    setCaretPosition(len);/*w ww  .j  a  v a2 s  . c  o  m*/
    setCharacterAttributes(aset, false);
    replaceSelection(s);
}

From source file:StylesExample7.java

public static void addText(JTextPane pane, StyleContext sc, Style logicalStyle, Paragraph[] content) {
    // The outer loop adds paragraphs, while the
    // inner loop adds character runs.
    int paragraphs = content.length;
    for (int i = 0; i < paragraphs; i++) {
        Run[] runs = content[i].content;
        for (int j = 0; j < runs.length; j++) {
            pane.setCharacterAttributes(
                    runs[j].styleName == null ? SimpleAttributeSet.EMPTY : sc.getStyle(runs[j].styleName),
                    true);/*from w  w w  .j ava2 s  .  c o m*/
            pane.replaceSelection(runs[j].content);
        }

        // At the end of the paragraph, add the logical style and
        // any overriding paragraph style and then terminate the 
        // paragraph with a newline.
        pane.setParagraphAttributes(SimpleAttributeSet.EMPTY, true);

        if (logicalStyle != null) {
            pane.setLogicalStyle(logicalStyle);
        }

        if (content[i].styleName != null) {
            pane.setParagraphAttributes(sc.getStyle(content[i].styleName), false);
        }

        pane.replaceSelection("\n");
    }
}

From source file:ParenMatcher.java

public ParenMatcher() {
    // create an array of AttributeSets from the array of Colors
    StyleContext sc = StyleContext.getDefaultStyleContext();
    badAttrSet = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, badColor);
    matchAttrSet = new AttributeSet[matchColor.length];
    for (int j = 0; j < matchColor.length; j += 1)
        matchAttrSet[j] = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, matchColor[j]);
}

From source file:Main.java

private void appendToPane(JTextPane tp, String msg, Color c) {
    StyleContext sc = StyleContext.getDefaultStyleContext();
    AttributeSet aset = sc.addAttribute(SimpleAttributeSet.EMPTY, StyleConstants.Foreground, c);

    aset = sc.addAttribute(aset, StyleConstants.FontFamily, "Lucida Console");
    aset = sc.addAttribute(aset, StyleConstants.Alignment, StyleConstants.ALIGN_JUSTIFIED);

    int len = tp.getDocument().getLength();
    tp.setCaretPosition(len);/*w w  w .  j  a  v  a 2 s.  c om*/
    tp.setCharacterAttributes(aset, false);
    tp.replaceSelection(msg);
}

From source file:ExtendedParagraphExample.java

public static void addText(JTextPane pane, StyleContext sc, Style logicalStyle, Paragraph[] content) {
    // The outer loop adds paragraphs, while the
    // inner loop adds character runs.
    int paragraphs = content.length;
    for (int i = 0; i < paragraphs; i++) {
        Run[] runs = content[i].content;
        for (int j = 0; j < runs.length; j++) {
            pane.setCharacterAttributes(
                    runs[j].styleName == null ? SimpleAttributeSet.EMPTY : sc.getStyle(runs[j].styleName),
                    true);//from  w w w .j a  va  2  s.c  om
            pane.replaceSelection(runs[j].content);
        }

        // At the end of the paragraph, add the logical style and
        // any overriding paragraph style and then terminate the
        // paragraph with a newline.
        pane.setParagraphAttributes(SimpleAttributeSet.EMPTY, true);

        if (logicalStyle != null) {
            pane.setLogicalStyle(logicalStyle);
        }

        if (content[i].styleName != null) {
            pane.setParagraphAttributes(sc.getStyle(content[i].styleName), false);
        }

        if (i != paragraphs - 1) {
            pane.replaceSelection("\n");
        }
    }
}