Example usage for javax.swing.text SimpleAttributeSet SimpleAttributeSet

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

Introduction

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

Prototype

public SimpleAttributeSet() 

Source Link

Document

Creates a new attribute set.

Usage

From source file:Main.java

public TextPaneAttributes() {
    JTextPane textPane = new JTextPane();
    StyledDocument doc = textPane.getStyledDocument();
    MutableAttributeSet standard = new SimpleAttributeSet();

    StyleConstants.setAlignment(standard, StyleConstants.ALIGN_CENTER);
    doc.setParagraphAttributes(0, 0, standard, true);
    MutableAttributeSet keyWord = new SimpleAttributeSet();

    StyleConstants.setForeground(keyWord, Color.red);
    StyleConstants.setItalic(keyWord, true);

    textPane.setText("this is a test. \nthis is a four.");

    doc.setCharacterAttributes(0, 3, keyWord, false);
    doc.setCharacterAttributes(19, 4, keyWord, false);
    try {/*from ww w . j  a v a2 s  . co m*/
        doc.insertString(0, "Start of text\n", null);
        doc.insertString(doc.getLength(), "End of text\n", keyWord);
    } catch (Exception e) {
    }
    MutableAttributeSet selWord = new SimpleAttributeSet();

    StyleConstants.setForeground(selWord, Color.RED);
    StyleConstants.setItalic(selWord, true);

    JScrollPane scrollPane = new JScrollPane(textPane);
    scrollPane.setPreferredSize(new Dimension(200, 200));
    add(scrollPane);

    JButton toggleButton = new JButton("Find 'four'");
    toggleButton.addActionListener(e -> {
        int index = textPane.getText().indexOf("four");
        StyledDocument doc1 = textPane.getStyledDocument();
        doc1.setCharacterAttributes(index, 4, selWord, false);
    });
    add(toggleButton, BorderLayout.SOUTH);
}

From source file:Main.java

public Main() throws Exception {
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane().add(edit);/*from  w w  w.  j  a  va 2 s  .  c o  m*/
    edit.setEditorKit(new MyEditorKit());
    SimpleAttributeSet attrs = new SimpleAttributeSet();
    StyleConstants.setAlignment(attrs, StyleConstants.ALIGN_CENTER);
    StyledDocument doc = (StyledDocument) edit.getDocument();
    doc.insertString(0, "111\n2222222\n3333", attrs);
    doc.setParagraphAttributes(0, doc.getLength() - 1, attrs, false);

    frame.setSize(300, 300);
    frame.setVisible(true);
}

From source file:Tela.java

/**
 * Creates new form Tela/* ww  w  . java 2  s . c  o  m*/
 */
public Tela() {
    initComponents();
    jPanel2.setLayout(new BorderLayout());
    exibeGrafico(new ArrayList<Double>());

    this.setVisible(true);

    StyledDocument doc = txtArtigos.getStyledDocument();
    SimpleAttributeSet center = new SimpleAttributeSet();
    doc.setParagraphAttributes(0, doc.getLength(), center, false);
}

From source file:com.clank.launcher.swing.MessageLog.java

public MessageLog(int numLines, boolean colorEnabled) {
    this.numLines = numLines;
    this.colorEnabled = colorEnabled;

    this.highlightedAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(highlightedAttributes, new Color(0xFF7F00));

    this.errorAttributes = new SimpleAttributeSet();
    StyleConstants.setForeground(errorAttributes, new Color(0xFF0000));
    this.infoAttributes = new SimpleAttributeSet();
    this.debugAttributes = new SimpleAttributeSet();

    setLayout(new BorderLayout());

    initComponents();/*from   w ww  .  ja  v  a 2s . c  o m*/
}

From source file:de.codesourcery.jasm16.ide.ui.views.CPUView.java

protected final static SimpleAttributeSet createStyle(Color color) {
    SimpleAttributeSet result = new SimpleAttributeSet();
    StyleConstants.setForeground(result, color);
    return result;
}

From source file:coolmap.application.widget.impl.console.WidgetConsole.java

public void logError(String message) {
    message = message.replaceAll("\n", "\n  ");
    message = "> " + message.trim();
    message += "\n";
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setBold(aset, true);
    StyleConstants.setForeground(aset, UI.colorAKABENI);
    appendToPane(message, aset);// w ww.  ja v a2s . com
}

From source file:FontPicker.java

public FontChooser(Frame parent) {
    super(parent, "Font Chooser", true);
    setSize(450, 450);/*from   www. j ava  2  s.  c  o  m*/
    attributes = new SimpleAttributeSet();

    // Make sure that any way the user cancels the window does the right
    // thing
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            closeAndCancel();
        }
    });

    // Start the long process of setting up our interface
    Container c = getContentPane();

    JPanel fontPanel = new JPanel();
    fontName = new JComboBox(new String[] { "TimesRoman", "Helvetica", "Courier" });
    fontName.setSelectedIndex(1);
    fontName.addActionListener(this);
    fontSize = new JTextField("12", 4);
    fontSize.setHorizontalAlignment(SwingConstants.RIGHT);
    fontSize.addActionListener(this);
    fontBold = new JCheckBox("Bold");
    fontBold.setSelected(true);
    fontBold.addActionListener(this);
    fontItalic = new JCheckBox("Italic");
    fontItalic.addActionListener(this);

    fontPanel.add(fontName);
    fontPanel.add(new JLabel(" Size: "));
    fontPanel.add(fontSize);
    fontPanel.add(fontBold);
    fontPanel.add(fontItalic);

    c.add(fontPanel, BorderLayout.NORTH);

    // Set up the color chooser panel and attach a change listener so that
    // color
    // updates get reflected in our preview label.
    colorChooser = new JColorChooser(Color.black);
    colorChooser.getSelectionModel().addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            updatePreviewColor();
        }
    });
    c.add(colorChooser, BorderLayout.CENTER);

    JPanel previewPanel = new JPanel(new BorderLayout());
    previewLabel = new JLabel("Here's a sample of this font.");
    previewLabel.setForeground(colorChooser.getColor());
    previewPanel.add(previewLabel, BorderLayout.CENTER);

    // Add in the Ok and Cancel buttons for our dialog box
    JButton okButton = new JButton("Ok");
    okButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            closeAndSave();
        }
    });
    JButton cancelButton = new JButton("Cancel");
    cancelButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            closeAndCancel();
        }
    });

    JPanel controlPanel = new JPanel();
    controlPanel.add(okButton);
    controlPanel.add(cancelButton);
    previewPanel.add(controlPanel, BorderLayout.SOUTH);

    // Give the preview label room to grow.
    previewPanel.setMinimumSize(new Dimension(100, 100));
    previewPanel.setPreferredSize(new Dimension(100, 100));

    c.add(previewPanel, BorderLayout.SOUTH);
}

From source file:coolmap.application.widget.impl.console.WidgetConsole.java

public void logWaring(String message) {
    message = message.replaceAll("\n", "\n  ");
    message = "> " + message.trim();
    message += "\n";
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setBold(aset, true);
    StyleConstants.setForeground(aset, UI.colorOrange0);
    appendToPane(message, aset);//from  w ww . ja  va2s .c om
}

From source file:coolmap.application.widget.impl.console.WidgetConsole.java

public void logInfo(String message) {
    message = message.replaceAll("\n", "\n  ");
    message = "> " + message.trim();
    message += "\n";
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setForeground(aset, UI.colorMIDORI);
    StyleConstants.setBold(aset, true);
    appendToPane(message, aset);//from ww w. j a v a 2s.  c o m
}

From source file:coolmap.application.widget.impl.console.WidgetConsole.java

public void logData(String message) {
    message = message.replaceAll("\n", "\n  ");
    message = "> " + message.trim();
    message += "\n\n";
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setForeground(aset, UI.colorMIDORI);
    StyleConstants.setBold(aset, true);
    appendToPane(message, aset);//from  w w  w  .j  av a  2s. c om
}