Example usage for javax.swing.text MutableAttributeSet addAttribute

List of usage examples for javax.swing.text MutableAttributeSet addAttribute

Introduction

In this page you can find the example usage for javax.swing.text MutableAttributeSet addAttribute.

Prototype

public void addAttribute(Object name, Object value);

Source Link

Document

Creates a new attribute set similar to this one except that it contains an attribute with the given name and value.

Usage

From source file:Main.java

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

    JTextPane pane = new JTextPane();
    pane.setEditorKit(new CustomEditorKit());
    pane.setText("Underline With Different Color");

    StyledDocument doc = (StyledDocument) pane.getDocument();
    MutableAttributeSet attrs = new SimpleAttributeSet();
    attrs.addAttribute("Underline-Color", Color.red);
    doc.setCharacterAttributes(0, doc.getLength() - 1, attrs, true);

    JScrollPane sp = new JScrollPane(pane);
    frame.setContentPane(sp);/* ww w.j a  v a  2s  .  c om*/
    frame.setPreferredSize(new Dimension(400, 300));
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
}

From source file:Main.java

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

    JEditorPane pane = new JEditorPane();
    pane.setEditorKit(new NewEditorKit());
    pane.setText(/*w ww .  j a v a2  s  . c  o  m*/
            "test test test test test test test test test test test test test test test test test test test test test test test test test test test test test test ");

    StyledDocument doc = (StyledDocument) pane.getDocument();
    MutableAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute("strike-color", Color.red);
    doc.setCharacterAttributes(0, 9, attr, false);

    attr.addAttribute("strike-color", Color.blue);
    doc.setCharacterAttributes(10, 19, attr, false);
    JScrollPane sp = new JScrollPane(pane);

    fr.getContentPane().add(sp);
    fr.setSize(300, 300);
    fr.setLocationRelativeTo(null);
    fr.setVisible(true);
}

From source file:ExtendedParagraphExample.java

public static void setParagraphBackground(MutableAttributeSet a, Color c) {
    a.addAttribute(ParagraphBackground, c);
}

From source file:ExtendedParagraphExample.java

public static void setParagraphBorder(MutableAttributeSet a, Border b) {
    a.addAttribute(ParagraphBorder, b);
}

From source file:com.hexidec.ekit.component.RelativeImageView.java

/** Change the size of this image. This alters the HEIGHT and WIDTH
  * attributes of the Element and causes a re-layout.
  *///w w w .j  a v a2 s .c  om
protected void resize(int width, int height) {
    if ((width == fWidth) && (height == fHeight)) {
        return;
    }
    fWidth = width;
    fHeight = height;
    // Replace attributes in document
    MutableAttributeSet attr = new SimpleAttributeSet();
    attr.addAttribute(HTML.Attribute.WIDTH, Integer.toString(width));
    attr.addAttribute(HTML.Attribute.HEIGHT, Integer.toString(height));
    ((StyledDocument) getDocument()).setCharacterAttributes(fElement.getStartOffset(), fElement.getEndOffset(),
            attr, false);
}

From source file:org.pmedv.core.components.RelativeImageView.java

/**
 * Change the size of this image. This alters the HEIGHT and WIDTH
 * attributes of the Element and causes a re-layout.
 *//*from  w ww. j  a va2  s .c  o  m*/
protected void resize(int width, int height) {

    if ((width == fWidth) && (height == fHeight)) {
        return;
    }
    fWidth = width;
    fHeight = height;
    // Replace attributes in document
    MutableAttributeSet myAttr = new SimpleAttributeSet();
    myAttr.addAttribute(HTML.Attribute.WIDTH, Integer.toString(width));
    myAttr.addAttribute(HTML.Attribute.HEIGHT, Integer.toString(height));
    ((StyledDocument) getDocument()).setCharacterAttributes(fElement.getStartOffset(), fElement.getEndOffset(),
            myAttr, false);
}