Java JTextPane centerText(JTextPane pane)

Here you can find the source of centerText(JTextPane pane)

Description

center Text

License

LGPL

Declaration

public static void centerText(JTextPane pane) 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import javax.swing.JTextPane;

import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;

public class Main {
    public static void centerText(JTextPane pane) {
        StyledDocument doc = pane.getStyledDocument();
        SimpleAttributeSet center = new SimpleAttributeSet();
        StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
        doc.setParagraphAttributes(0, doc.getLength(), center, false);
    }//  ww  w . jav a2s  .  c  o  m
}

Related

  1. appendAsGreen(JTextPane pane, String fontName, int fontSize, String s)
  2. appendAsMessage(JTextPane pane, String fontName, int fontSize, String s)
  3. appendString(String str, JTextPane jtext)
  4. appendToPane(JTextPane textPane, String text, Color foregroundColor, Color backgroundColor)
  5. applyRegex(String regex, JTextPane pane, Color highlightColor)
  6. createJTextPane(String text, Color backgroundColor)
  7. createTextPaneScrollPane(JTextPane textPane)
  8. getFontFamily(JTextPane textPane)
  9. getForegroundColor(JTextPane textPane)