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:Main.java

private void changeStyle() {
    StyledDocument doc = (StyledDocument) textPane.getDocument();
    int selectionEnd = textPane.getSelectionEnd();
    int selectionStart = textPane.getSelectionStart();
    if (selectionStart == selectionEnd) {
        return;//w ww  . j ava 2s.  co m
    }
    Element element = doc.getCharacterElement(selectionStart);
    AttributeSet as = element.getAttributes();

    MutableAttributeSet asNew = new SimpleAttributeSet(as.copyAttributes());
    StyleConstants.setBold(asNew, !StyleConstants.isBold(as));
    doc.setCharacterAttributes(selectionStart, textPane.getSelectedText().length(), asNew, true);
    String text = (StyleConstants.isBold(as) ? "Cancel Bold" : "Bold");
    btnStyle.setText(text);
}

From source file:Main.java

@Override
public void run() {
    for (int i = 0; i < fnt.length; i++) {
        StyleConstants.setBold(mas, false);
        StyleConstants.setItalic(mas, false);
        StyleConstants.setFontFamily(mas, fnt[i]);
        StyleConstants.setFontSize(mas, 16);
        dis(fnt[i]);//w w  w  . j  av a 2 s .  c  om
        try {
            Thread.sleep(75);
        } catch (Exception e) {
            e.printStackTrace();
        }
        StyleConstants.setBold(mas, true);
        dis(fnt[i] + " Bold");
        try {
            Thread.sleep(75);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    jta.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}

From source file:com.croer.javaorange.diviner.SimpleOrangeTextPane.java

public SimpleOrangeTextPane() {
    CONFIGURATION = Configuration.getCONFIGURATION();

    //Create the style array to show the colors 
    List<Object> colorList = CONFIGURATION.getList("ColorWord");
    styles = new Style[colorList.size()];
    StyleContext sc = new StyleContext();
    for (int i = 0; i < colorList.size(); i++) {
        styles[i] = sc.addStyle((String) colorList.get(i), sc.getStyle(StyleContext.DEFAULT_STYLE));
        StyleConstants.setForeground(styles[i], ColorUtils.getColorByName((String) colorList.get(i)));
        StyleConstants.setBold(styles[i], true);
    }//from  w w w  .  j  a v a 2s . c  om

    //Deactive key bindings 
    List<Object> navigationList = CONFIGURATION.getList("PageNavigation");
    for (Object object : navigationList) {
        getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(object.toString()), "none");
    }

    //Get the document for adding a document listener
    dsd = (DefaultStyledDocument) getDocument();
    dsd.addDocumentListener(new DocumentListenerTextPane());

    //...and setting a document filter
    documentFilter = new MyDocumentFilter();
    dsd.setDocumentFilter(documentFilter);
}

From source file:edu.scripps.fl.pubchem.xmltool.gui.GUIComponent.java

protected void addStylesToDocument(StyledDocument doc) {
    //Initialize some styles.
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);

    Style regular = doc.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");

    Style s = doc.addStyle("italic", regular);
    StyleConstants.setItalic(s, true);

    s = doc.addStyle("bold", regular);
    StyleConstants.setBold(s, true);

    s = doc.addStyle("right", regular);
    StyleConstants.setAlignment(s, StyleConstants.ALIGN_RIGHT);
}

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  w  w.  j a va2s.  c  o  m*/
}

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  ww  w  . j a v a2  s .  c  o  m
}

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);/*w ww  .j av a2s .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. ja v  a  2s  . co  m
}

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

public void log(String message) {
    message = message.replaceAll("\n", "\n  ");
    message = "> " + message.trim();
    message += "\n";
    SimpleAttributeSet aset = new SimpleAttributeSet();
    StyleConstants.setForeground(aset, UI.colorBlack2);
    StyleConstants.setBold(aset, false);
    appendToPane(message, aset);/*from   w w  w . ja  v a 2 s  . co m*/
}

From source file:MainClass.java

public void actionPerformed(ActionEvent e) {
    JEditorPane editor = getEditor(e);
    if (editor != null) {
        StyledEditorKit kit = getStyledEditorKit(editor);
        MutableAttributeSet attr = kit.getInputAttributes();
        boolean bold = (StyleConstants.isBold(attr)) ? false : true;
        SimpleAttributeSet sas = new SimpleAttributeSet();
        StyleConstants.setBold(sas, bold);
        setCharacterAttributes(editor, sas, false);

    }/*from  w  w w.jav  a2s.  c  o m*/
}