TextPane.java

package window;

import java.awt.*;
import java.awt.Color;
import javax.swing.*;
import javax.swing.text.*;

public class TextPane extends JTextPane {

  public void append(SimpleAttributeSet sas, String str) {
    // put the text in a showed place
    int length = this.getDocument().getLength();
    this.setCaretPosition(length);
    this.setCharacterAttributes(sas, false);
    this.replaceSelection(str);
  }

  public void append(String str) {
    SimpleAttributeSet sas = new SimpleAttributeSet();
    sas.getAttribute(this);
    append(sas, str);
  }

  public void append(Font font, Boolean bb, Boolean ib, Boolean ub, Color bc, Color fc, String str) {
    // set the text style
    SimpleAttributeSet sas = new SimpleAttributeSet();
    sas.addAttribute(StyleConstants.FontFamily, font.getFamily());
    sas.addAttribute(StyleConstants.FontSize, new Integer(font.getSize()));
    sas.addAttribute(StyleConstants.Bold, bb);
    sas.addAttribute(StyleConstants.Italic, ib);
    sas.addAttribute(StyleConstants.Underline, ub);
    sas.addAttribute(StyleConstants.Background, bc);
    sas.addAttribute(StyleConstants.Foreground, fc);

    append(sas, str);
  }

  public void append(Boolean bb, Boolean ib, Boolean ub, Color bc, Color fc, String str) {
    append(this.getFont(), bb, ib, ub, bc, fc, str);
  }

  public void append(Color bc, Color fc, String str) {
    append(this.getFont(), Boolean.FALSE, Boolean.FALSE, Boolean.FALSE, bc, fc, str);
  }

  // you can freely modify this method
  public void append(Boolean bb, Color fc, String str) {
    append(this.getFont(), bb, Boolean.FALSE, Boolean.FALSE, this.getBackground(), fc, str);
  }
}