Class ScrollableTextArea

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible, ScrollPaneConstants

public class ScrollableTextArea extends JScrollPane
A JScrollPane wrapper for a text area that can be told to scroll to bottom
See Also:
  • Constructor Details

    • ScrollableTextArea

      public ScrollableTextArea()
      Constructs a scrollable JTextArea, where a default model is set, the initial string is null, and rows/columns are set to 0.
    • ScrollableTextArea

      public ScrollableTextArea(String text)
      Constructs a scrollable JextArea with the specified text displayed. A default model is created and rows/columns are set to 0.
      Parameters:
      text - the initial text.
    • ScrollableTextArea

      public ScrollableTextArea(int rows, int columns)
      Constructs a new empty TextArea with the specified number of rows and columns. A default model is created, and the initial string is null.
      Parameters:
      rows - the number of visible rows.
      columns - the number of visible columns.
    • ScrollableTextArea

      public ScrollableTextArea(String text, int rows, int columns)
      Constructs a scrollable JTextArea with the specified text and number of rows and columns. A default model is created.
      Parameters:
      text - initial text.
      rows - the number of visible rows.
      columns - the number of visible columns.
    • ScrollableTextArea

      public ScrollableTextArea(Document doc)
      Constructs a scrollable JTextArea with the given document model, and defaults for all of the other arguments (null, 0, 0).
      Parameters:
      doc - - the model to use
    • ScrollableTextArea

      public ScrollableTextArea(Document doc, String text, int rows, int columns)
      Constructs a scrollable JTextArea with the specified number of rows and columns, and the given model. All of the constructors feed through this constructor.
      Parameters:
      doc - - the model to use
      text - initial text.
      rows - the number of visible rows.
      columns - the number of visible columns.
  • Method Details

    • append

      public void append(String text)
      Appends the text to the text area maintained in this scroll pane
      Parameters:
      text - the text to append.
    • getLineCount

      public int getLineCount()
      Returns the number of lines current set in the text area
      Returns:
      the count
    • getTabSize

      public int getTabSize()
      Returns the tab size set in the text area
      Returns:
      the size
    • getTextAreaHeight

      public int getTextAreaHeight()
      Returns the total area height of the text area (row height * line count)
      Returns:
      the height
    • getTextVisibleHeight

      public int getTextVisibleHeight()
      Returns the visible height of the text area
      Returns:
      the height
    • insert

      public void insert(String text, int position)
      Inserts the string at the specified position
      Parameters:
      text - the text to insert.
      position - the character postition at which to insert the text.
    • replaceRange

      public void replaceRange(String text, int start, int end)
      replaces the range of text specified
      Parameters:
      text - the new text that will replace the old text.
      start - the starting character postition of the text to replace.
      end - the ending character position of the text to replace.
    • setCaretPosition

      public void setCaretPosition(int position)
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • scrollToBottom

      public void scrollToBottom()
      forces the scroll pane to scroll to bottom of text area
    • scrollToTop

      public void scrollToTop()
      Scroll the pane to the top of the text area.
    • setTabSize

      public void setTabSize(int tabSize)
      Sets the number of characters to expand tabs to. This will be multiplied by the maximum advance for variable width fonts. A PropertyChange event ("tabSize") is fired when tab size changes.
      Parameters:
      tabSize - the new tab size.
    • setText

      public void setText(String text)
      set the text in the text area
      Parameters:
      text - the text to set.
    • getText

      public String getText()
      Returns the text contained within the text area
      Returns:
      the text
    • setEditable

      public void setEditable(boolean editable)
      Sets the ability to edit the text area content
      Parameters:
      editable - true to edit, false to not allow edit.