charvax.swing

Class JTextArea

Implemented Interfaces:
Scrollable

public class JTextArea
extends JTextComponent
implements Scrollable

JTextArea is an (optionally editable) multi-line area that displays plain text. The JTextArea class implements the Scrollable interface, which enables it to be placed inside a charvax.swing.JScrollPane. In fact, in the CHARVA framework it should ALWAYS be used inside a JScrollPane, otherwise it will be unusable (its size depends on the text it contains).

Note that, unlike the javax.swing.JTextArea, pressing the TAB key while the keyboard focus is in the JTextArea will not cause a tab to be inserted; instead, it will move the keyboard input focus to the next focus-traversable component (if there is one). This is because (in javax.swing) the user can user can use the mouse to move the keyboard input focus away from the JTextArea, whereas CHARVA has no mouse support.

Field Summary

Fields inherited from class charvax.swing.text.JTextComponent

_caretPosition, _document, _editable

Fields inherited from class charvax.swing.JComponent

_border

Fields inherited from class charva.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT, _alignmentX, _alignmentY, _background, _cursesColor, _enabled, _focusListeners, _foreground, _keyListeners, _origin, _parent, _visible

Constructor Summary

JTextArea()
The default constructor creates an empty text area with 10 rows and 10 columns.
JTextArea(String text_)
Construct a text area with 10 rows and 10 columns, and containing the specified text.
JTextArea(String text_, int rows_, int columns_)
Construct a text area wth the specified number of rows and columns, and containing the specified text.

Method Summary

void
addScrollListener(ScrollListener sl_)
Register a ScrollListener object for this JTextArea.
void
append(String text_)
Appends the specified text to the end of the document.
void
debug(int level_)
void
draw()
Implements the abstract method in charva.awt.Component.
int
getColumns()
Returns the number of columns in this JTextArea.
int
getHeight()
int
getLineCount()
Returns the number of lines of text displayed in the JTextArea.
int
getLineEndOffset(int line_)
Returns the offset of the last character in the specified line.
int
getLineOfOffset(int offset_)
Translates an offset (relative to the start of the document) to a line number.
int
getLineStartOffset(int line_)
Returns the offset of the first character in the specified line of text.
boolean
getLineWrap()
Returns the line-wrapping policy of the JTextArea.
Dimension
getPreferredScrollableViewportSize()
Returns the preferred size of the viewport for this JTextArea when it is in a JScrollPane (this method implements the Scrollable interface).
int
getRows()
Returns the number of rows in this JTextArea.
Dimension
getSize()
Returns the size of this component.
int
getWidth()
boolean
getWrapStyleWord()
Returns the line-wrapping style to be used if getLineWrap() is true.
void
insert(String text_, int pos_)
Inserts the specified text at the specified position (ie at the specified offset from the start of the document)..
Dimension
minimumSize()
Called by the LayoutManager.
void
processKeyEvent(KeyEvent ke_)
Process KeyEvents that have been generated by this JTextArea.
void
processMouseEvent(MouseEvent e_)
Process a MouseEvent that was generated by clicking the mouse somewhere inside this JTextArea.
void
processScrollEvent(ScrollEvent e_)
Process scroll events generated by this JTextArea.
void
removeScrollListener(ScrollListener sl_)
Remove a ScrollListener object that is registered for this JTextArea.
void
replaceRange(String text_, int start_, int end_)
Replaces the text from the specified start position to end position with the specified text.
void
requestFocus()
This method should be invoked by all subclasses of Component which override this method; because this method generates the FOCUS_GAINED event when the component gains the keyboard focus.
void
setCaretPosition(int caret_)
Sets the position of the text insertion caret for this JTextArea.
void
setColumns(int columns_)
Sets the number of columns in this JTextArea.
void
setLineWrap(boolean wrap_)
Sets the line-wrapping policy of the JTextArea.
void
setRows(int rows_)
Sets the number of rows in this JTextArea.
void
setWrapStyleWord(boolean wrapWord_)
Sets the line-wrapping style to be used if getLineWrap() is true.

Methods inherited from class charvax.swing.text.JTextComponent

getCaretPosition, getDocument, getText, isEditable, setCaretPosition, setDocument, setEditable, setText

Methods inherited from class charvax.swing.JComponent

draw, getBorder, getInsets, setBorder

Methods inherited from class charva.awt.Component

addFocusListener, addKeyListener, contains, contains, debug, draw, getAlignmentX, getAlignmentY, getAncestorWindow, getBackground, getBounds, getCursesColor, getForeground, getHeight, getLocation, getLocationOnScreen, getName, getParent, getSize, getWidth, hasFocus, hide, invalidate, isDisplayed, isEnabled, isFocusTraversable, isTotallyObscured, isValid, isVisible, minimumSize, processEvent, processFocusEvent, processKeyEvent, processMouseEvent, repaint, requestFocus, requestSync, setBackground, setEnabled, setForeground, setLocation, setLocation, setName, setParent, setVisible, show, validate, validateCursesColor

Constructor Details

JTextArea

public JTextArea()
The default constructor creates an empty text area with 10 rows and 10 columns.

JTextArea

public JTextArea(String text_)
Construct a text area with 10 rows and 10 columns, and containing the specified text.

JTextArea

public JTextArea(String text_,
                 int rows_,
                 int columns_)
Construct a text area wth the specified number of rows and columns, and containing the specified text.

Method Details

addScrollListener

public void addScrollListener(ScrollListener sl_)
Register a ScrollListener object for this JTextArea.
Specified by:
addScrollListener in interface Scrollable

append

public void append(String text_)
Appends the specified text to the end of the document.

debug

public void debug(int level_)
Overrides:
debug in interface Component

draw

public void draw()
Implements the abstract method in charva.awt.Component.
Overrides:
draw in interface JComponent

getColumns

public int getColumns()
Returns the number of columns in this JTextArea.

getHeight

public int getHeight()
Overrides:
getHeight in interface Component

getLineCount

public int getLineCount()
Returns the number of lines of text displayed in the JTextArea.

getLineEndOffset

public int getLineEndOffset(int line_)
Returns the offset of the last character in the specified line.

getLineOfOffset

public int getLineOfOffset(int offset_)
Translates an offset (relative to the start of the document) to a line number.

getLineStartOffset

public int getLineStartOffset(int line_)
Returns the offset of the first character in the specified line of text.

getLineWrap

public boolean getLineWrap()
Returns the line-wrapping policy of the JTextArea. If set to true, lines will be wrapped if they are too long to fit within the allocated width. If set to false, the lines will always be unwrapped.

getPreferredScrollableViewportSize

public Dimension getPreferredScrollableViewportSize()
Returns the preferred size of the viewport for this JTextArea when it is in a JScrollPane (this method implements the Scrollable interface). The size is determined by the number of rows and columns set for this JTextArea (either in the constructor or in the setColumns() and setRows() methods).
Specified by:
getPreferredScrollableViewportSize in interface Scrollable

getRows

public int getRows()
Returns the number of rows in this JTextArea.

getSize

public Dimension getSize()
Returns the size of this component.
Overrides:
getSize in interface Component

getWidth

public int getWidth()
Overrides:
getWidth in interface Component

getWrapStyleWord

public boolean getWrapStyleWord()
Returns the line-wrapping style to be used if getLineWrap() is true. If true, lines will be wrapped at word boundaries (whitespace) if they are too long to fit in the allocated number of columns. If false, lines will be wrapped at character boundaries.

insert

public void insert(String text_,
                   int pos_)
Inserts the specified text at the specified position (ie at the specified offset from the start of the document)..

minimumSize

public Dimension minimumSize()
Called by the LayoutManager.
Overrides:
minimumSize in interface Component

processKeyEvent

public void processKeyEvent(KeyEvent ke_)
Process KeyEvents that have been generated by this JTextArea.
Overrides:
processKeyEvent in interface Component

processMouseEvent

public void processMouseEvent(MouseEvent e_)
Process a MouseEvent that was generated by clicking the mouse somewhere inside this JTextArea. Clicking the mouse inside the JTextArea moves the caret position to where the mouse was clicked.
Overrides:
processMouseEvent in interface Component

processScrollEvent

public void processScrollEvent(ScrollEvent e_)
Process scroll events generated by this JTextArea.
Specified by:
processScrollEvent in interface Scrollable

removeScrollListener

public void removeScrollListener(ScrollListener sl_)
Remove a ScrollListener object that is registered for this JTextArea.
Specified by:
removeScrollListener in interface Scrollable

replaceRange

public void replaceRange(String text_,
                         int start_,
                         int end_)
Replaces the text from the specified start position to end position with the specified text.

requestFocus

public void requestFocus()
This method should be invoked by all subclasses of Component which override this method; because this method generates the FOCUS_GAINED event when the component gains the keyboard focus.
Overrides:
requestFocus in interface Component

setCaretPosition

public void setCaretPosition(int caret_)
Sets the position of the text insertion caret for this JTextArea.
Overrides:
setCaretPosition in interface JTextComponent

setColumns

public void setColumns(int columns_)
Sets the number of columns in this JTextArea.

setLineWrap

public void setLineWrap(boolean wrap_)
Sets the line-wrapping policy of the JTextArea. If set to true, lines will be wrapped if they are too long to fit within the allocated width. If set to false, the lines will always be unwrapped. The default value of this property is false.

setRows

public void setRows(int rows_)
Sets the number of rows in this JTextArea.

setWrapStyleWord

public void setWrapStyleWord(boolean wrapWord_)
Sets the line-wrapping style to be used if getLineWrap() is true. If true, lines will be wrapped at word boundaries (whitespace) if they are too long to fit in the allocated number of columns. If false, lines will be wrapped at character boundaries. The default value of this property is false.