Java JTextPane createJTextPane(String text, Color backgroundColor)

Here you can find the source of createJTextPane(String text, Color backgroundColor)

Description

Creates a new JTextPane object with the given properties.

License

Open Source License

Parameter

Parameter Description
text The text which will appear in the text pane
backgroundColor The background color

Return

A JTextPane object

Declaration

public static JTextPane createJTextPane(String text, Color backgroundColor) 

Method Source Code


//package com.java2s;
import java.awt.Color;

import java.awt.Font;

import javax.swing.JTextPane;

public class Main {
    /**//from   www .  j  a v a2 s.  c om
     * Creates a new <code>JTextPane</code> object with the given properties.
     *
     * @param text The text which will appear in the text pane
     * @param backgroundColor The background color
     * @return A <code>JTextPane</code> object
     */
    public static JTextPane createJTextPane(String text, Color backgroundColor) {
        JTextPane jTextPane = new JTextPane();
        jTextPane.setBorder(null);
        jTextPane.setEditable(false);
        jTextPane.setBackground(backgroundColor);
        jTextPane.setFont(new Font("Times New Roman", Font.PLAIN, 14));
        if (text != null) {
            jTextPane.setText(text);
        }
        jTextPane.setVerifyInputWhenFocusTarget(false);
        jTextPane.setAutoscrolls(false);
        return jTextPane;
    }
}

Related

  1. appendAsMessage(JTextPane pane, String fontName, int fontSize, String s)
  2. appendString(String str, JTextPane jtext)
  3. appendToPane(JTextPane textPane, String text, Color foregroundColor, Color backgroundColor)
  4. applyRegex(String regex, JTextPane pane, Color highlightColor)
  5. centerText(JTextPane pane)
  6. createTextPaneScrollPane(JTextPane textPane)
  7. getFontFamily(JTextPane textPane)
  8. getForegroundColor(JTextPane textPane)
  9. insertStyledString(JTextPane textPane, String text, SimpleAttributeSet attrSet, Color background, Color foreground, String fontFamily, int fontSize, boolean bold, boolean italic, boolean underline, boolean strikeThrough, Boolean superscript)