Example usage for javax.swing.text StyleConstants setLineSpacing

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

Introduction

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

Prototype

public static void setLineSpacing(MutableAttributeSet a, float i) 

Source Link

Document

Sets line spacing.

Usage

From source file:dylemator.DylematorUI.java

private void displayCenteredText(String text) {
    textArea.setText("");
    text = "\n\n\n" + text;
    SimpleAttributeSet attribs = new SimpleAttributeSet();
    if (sd == null)
        sd = new SettingsDialog(this, true);
    float fnt = sd.getFontSize();
    StyledDocument doc = (StyledDocument) textArea.getDocument();
    Style style = doc.getStyle(StyleContext.DEFAULT_STYLE);//doc.addStyle("MyStyle",null);
    StyleConstants.setFontSize(style, (int) fnt);
    StyleConstants.setLineSpacing(attribs, 0.5f);
    StyleConstants.setFontFamily(style, "Segoe UI");
    StyleConstants.setAlignment(attribs, StyleConstants.ALIGN_CENTER);
    textArea.setParagraphAttributes(attribs, true);

    try {/*from  w  ww  .  ja  va 2 s. c  om*/
        doc.insertString(doc.getLength(), text, style);
        doc.setParagraphAttributes(0, doc.getLength() - 1, attribs, false);
    } catch (BadLocationException ex) {
        Logger.getLogger(DylematorUI.class.getName()).log(Level.SEVERE, null, ex);
    }

}