Example usage for javax.swing.text StyleConstants setAlignment

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

Introduction

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

Prototype

public static void setAlignment(MutableAttributeSet a, int align) 

Source Link

Document

Sets alignment.

Usage

From source file:org.optaplanner.benchmark.impl.aggregator.swingui.BenchmarkAggregatorFrame.java

private JComponent createNoPlannerFoundTextField() {
    String infoMessage = "No planner benchmarks have been found in the benchmarkDirectory ("
            + benchmarkAggregator.getBenchmarkDirectory() + ").";
    JTextPane textPane = new JTextPane();

    textPane.setEditable(false);//from  w ww  .  ja  v  a2  s  .  com
    textPane.setText(infoMessage);

    // center info message
    StyledDocument styledDocument = textPane.getStyledDocument();
    SimpleAttributeSet center = new SimpleAttributeSet();
    StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
    StyleConstants.setBold(center, true);
    styledDocument.setParagraphAttributes(0, styledDocument.getLength(), center, false);
    return textPane;
}

From source file:org.smart.migrate.ui.ImportThread.java

private 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("small", regular);
    StyleConstants.setFontSize(s, 10);

    s = doc.addStyle("large", regular);
    StyleConstants.setFontSize(s, 16);

    s = doc.addStyle("icon", regular);
    StyleConstants.setAlignment(s, StyleConstants.ALIGN_CENTER);

    s = doc.addStyle("info", regular);
    StyleConstants.setForeground(s, Color.blue);

    s = doc.addStyle("error", regular);
    StyleConstants.setForeground(s, Color.red);

    s = doc.addStyle("warning", regular);
    StyleConstants.setForeground(s, Color.orange);

    s = doc.addStyle("gray", regular);
    StyleConstants.setForeground(s, Color.gray);

    s = doc.addStyle("success", regular);
    StyleConstants.setForeground(s, Color.green);
}