Class BaseTextPane

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, Scrollable, TextPaneComponent

public class BaseTextPane extends JTextPane implements TextPaneComponent
A customized JTextPane. Adds functionality for wordwrap, printing and selecting fonts.
Author:
fracpete (fracpete at waikato dot ac dot nz)
See Also:
  • Constructor Details

    • BaseTextPane

      public BaseTextPane()
      Creates a new BaseTextPane. A new instance of StyledEditorKit is created and set, and the document model set to null.
    • BaseTextPane

      public BaseTextPane(StyledDocument doc)
      Creates a new BaseTextPane, with a specified document model. A new instance of javax.swing.text.StyledEditorKit is created and set.
      Parameters:
      doc - the document model
  • Method Details

    • initialize

      protected void initialize()
      Initializes the member variables.
    • getParentFrame

      public Frame getParentFrame()
      Tries to determine the frame the container is part of.
      Returns:
      the parent frame if one exists or null if not
    • getParentDialog

      public Dialog getParentDialog()
      Tries to determine the dialog this panel is part of.
      Returns:
      the parent dialog if one exists or null if not
    • getParentInternalFrame

      public JInternalFrame getParentInternalFrame()
      Tries to determine the internal frame this panel is part of.
      Returns:
      the parent internal frame if one exists or null if not
    • printText

      public void printText()
      Pops up a print dialog.
    • selectFont

      public void selectFont()
      Pops up a dialog for selecting the font.
    • setTextFont

      public void setTextFont(Font font)
      Sets the font of the text pane. 2003-2007 Philip Isenhour, public domain, http://javatechniques.com/blog/setting-jtextpane-font-and-color/
      Parameters:
      font - the font to use
    • getLineCount

      public int getLineCount()
      Returns the number of lines in the document (= # of elements).
      Returns:
      the number of lines
    • gotoLine

      public boolean gotoLine(int line)
      Jumps to the specified line.
      Parameters:
      line - the 0-based index for the line
      Returns:
      true if successfully jumped
    • caretToLine

      public int caretToLine(int position)
      Determines the line number for the caret position.
      Parameters:
      position - the caret position
      Returns:
      the line number, -1 if failed to determine
    • append

      public void append(String text)
      Appends the text at the end.
      Parameters:
      text - the text to append
    • append

      public void append(String text, AttributeSet a)
      Appends the text at the end.
      Parameters:
      text - the text to append
      a - the attribute set, null if to use current
    • setCaretPositionLast

      public void setCaretPositionLast()
      Sets the position of the cursor at the end.
      Specified by:
      setCaretPositionLast in interface TextPaneComponent