textarea

textarea - CSc 2700: Lecture # 18 Textarea October 30, 2008...

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CSc 2700: Lecture # 18 Textarea October 30, 2008 1 Introduction A text field holds a single line of data; a text area holds multiple lines. The number of lines and length of each line are defined in the constructor. Moreover, a text area can also display horizontal and vertical scroll bars, if desired. Class: JTextArea Generates: ActionEvent when a user presses "Enter" Listener: Must implement ActionListener. Listener method to implement: void actionPerformed( ActionEvent e) Register a listener : void AddActionListener(ActionEvent e) Constructors: public JTextArea() instantiates a JTextArea object that displays no initial text. public JTextArea(String text) instantiates a JTextArea object that displays the string text. public JTextArea(int rows, int cols) instantiates a JTextArea object with rows rows and cols columns and displays no initial text. public JTextArea(String text, int rows, int cols) instantiates a JTextArea object, with rows rows and cols columns, that displays the string text. 1 Methods: void append(String text) appends text to the end of a text area. void insert (String text, int place) inserts text at position place. void replaceRange(String text, int start, int end) replaces the text from position start to position end with text. void setLineWrap(boolean wrap) If wrap is set to true, the lines will wrap in a text area. The default is false. boolean getLineWrap() returns true if line wrapping is enabled. void setWrapStyleWord(boolean wrap) If line wrap is enabled and wrap is set to true then lines wrap only at whitespace. That is, no single word appears on two lines. boolean getWrapStyleWord() returns true if word wrapping is enabled. void setRows(int rows) sets the number of rows of a text area to rows. int getRows() returns the number of visible rows. int getLineCount() returns the number of lines displayed in a text area. Lines are deter- mined by the newline character. A wrapped line does not constitute two lines. 2 In addition to the text area methods, JTextArea and JTextField inherit the following methods from JTextComponent. void copy() copies selected text to the system clipboard. Text is selected as you normally select text using an editor or a word processor. void cut() removes the selected text from the text area (field) and moves the text to the system clipboard. void paste() places the contents of the system clipboard into the text area (field) . If text in the component has been selected, that text is replaced. If text, is not selected, the clipboard text is inserted at the position of the cursor. void selectAll() marks as selected all the text in the component Additionally, these two methods can be used to read data from a file into a text area and write the data of a text area to a file....
View Full Document

Page1 / 10

textarea - CSc 2700: Lecture # 18 Textarea October 30, 2008...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online