Example usage for javax.swing.text StyleConstants setBold

List of usage examples for javax.swing.text StyleConstants setBold

Introduction

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

Prototype

public static void setBold(MutableAttributeSet a, boolean b) 

Source Link

Document

Sets the bold attribute.

Usage

From source file:uk.ac.kcl.texthunter.core.AnnotationEditor.java

private void updateInfoTextPane(String newText) {
    StyledDocument doc;/*from   w  w  w .ja v a 2  s .  com*/
    doc = infoTextPane.getStyledDocument();

    //  Define a keyword attribute

    SimpleAttributeSet newString = new SimpleAttributeSet();
    StyleConstants.setForeground(newString, Color.RED);
    StyleConstants.setBold(newString, true);

    SimpleAttributeSet oldString = new SimpleAttributeSet();
    StyleConstants.setForeground(oldString, Color.BLACK);
    StyleConstants.setBold(oldString, false);

    //  Add some text

    try {
        doc.setCharacterAttributes(0, doc.getLength(), oldString, true);
        doc.insertString(doc.getLength(), "\n" + newText, newString);
    } catch (Exception e) {
        System.out.println(e);
    }
}