TextArea.java revision 0
2362N/A * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved. 2178N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 2178N/A * This code is free software; you can redistribute it and/or modify it 2178N/A * under the terms of the GNU General Public License version 2 only, as 2178N/A * published by the Free Software Foundation. Sun designates this 2178N/A * particular file as subject to the "Classpath" exception as provided 2178N/A * by Sun in the LICENSE file that accompanied this code. 2178N/A * This code is distributed in the hope that it will be useful, but WITHOUT 2178N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 2178N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 2178N/A * version 2 for more details (a copy is included in the LICENSE file that 2178N/A * You should have received a copy of the GNU General Public License version 2178N/A * 2 along with this work; if not, write to the Free Software Foundation, 2362N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 2362N/A * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, 2178N/A * CA 95054 USA or visit www.sun.com if you need additional information or 2178N/A * A <code>TextArea</code> object is a multi-line region 2178N/A * that displays text. It can be set to allow editing or 2178N/A * The following image shows the appearance of a text area: 2178N/A * ALIGN=center HSPACE=10 VSPACE=7> 2178N/A * This text area could be created by the following line of code: 2178N/A * new TextArea("Hello", 5, 40); * The number of rows in the <code>TextArea</code>. * This parameter will determine the text area's height. * Guaranteed to be non-negative. * The number of columns in the <code>TextArea</code>. * A column is an approximate average character * width that is platform-dependent. * This parameter will determine the text area's width. * Guaranteed to be non-negative. * Create and display both vertical and horizontal scrollbars. * Create and display vertical scrollbar only. * Create and display horizontal scrollbar only. * Do not create or display any scrollbars for the text area. * Determines which scrollbars are created for the * text area. It can be one of four values : * <code>SCROLLBARS_BOTH</code> = both scrollbars.<BR> * <code>SCROLLBARS_HORIZONTAL_ONLY</code> = Horizontal bar only.<BR> * <code>SCROLLBARS_VERTICAL_ONLY</code> = Vertical bar only.<BR> * <code>SCROLLBARS_NONE</code> = No scrollbars.<BR> * @see #getScrollbarVisibility() * Cache the Sets of forward and backward traversal keys so we need not * look them up each time. * JDK 1.1 serialVersionUID * Initialize JNI field and method ids private static native void initIDs();
/* ensure that the necessary native libraries are loaded */ * Constructs a new text area with the empty string as text. * This text area is created with scrollbar visibility equal to * {@link #SCROLLBARS_BOTH}, so both vertical and horizontal * scrollbars will be visible for this text area. * @exception HeadlessException if * <code>GraphicsEnvironment.isHeadless</code> returns true * @see java.awt.GraphicsEnvironment#isHeadless() * Constructs a new text area with the specified text. * This text area is created with scrollbar visibility equal to * {@link #SCROLLBARS_BOTH}, so both vertical and horizontal * scrollbars will be visible for this text area. * @param text the text to be displayed; if * <code>text</code> is <code>null</code>, the empty * string <code>""</code> will be displayed * @exception HeadlessException if * <code>GraphicsEnvironment.isHeadless</code> returns true * @see java.awt.GraphicsEnvironment#isHeadless() * Constructs a new text area with the specified number of * rows and columns and the empty string as text. * A column is an approximate average character * width that is platform-dependent. The text area is created with * scrollbar visibility equal to {@link #SCROLLBARS_BOTH}, so both * vertical and horizontal scrollbars will be visible for this * @param rows the number of rows * @param columns the number of columns * @exception HeadlessException if * <code>GraphicsEnvironment.isHeadless</code> returns true * @see java.awt.GraphicsEnvironment#isHeadless() * Constructs a new text area with the specified text, * and with the specified number of rows and columns. * A column is an approximate average character * width that is platform-dependent. The text area is created with * scrollbar visibility equal to {@link #SCROLLBARS_BOTH}, so both * vertical and horizontal scrollbars will be visible for this * @param text the text to be displayed; if * <code>text</code> is <code>null</code>, the empty * string <code>""</code> will be displayed * @param rows the number of rows * @param columns the number of columns * @exception HeadlessException if * <code>GraphicsEnvironment.isHeadless</code> returns true * @see java.awt.GraphicsEnvironment#isHeadless() * Constructs a new text area with the specified text, * and with the rows, columns, and scroll bar visibility * as specified. All <code>TextArea</code> constructors defer to * The <code>TextArea</code> class defines several constants * that can be supplied as values for the * <code>scrollbars</code> argument: * <li><code>SCROLLBARS_BOTH</code>, * <li><code>SCROLLBARS_VERTICAL_ONLY</code>, * <li><code>SCROLLBARS_HORIZONTAL_ONLY</code>, * <li><code>SCROLLBARS_NONE</code>. * Any other value for the * <code>scrollbars</code> argument is invalid and will result in * this text area being created with scrollbar visibility equal to * the default value of {@link #SCROLLBARS_BOTH}. * @param text the text to be displayed; if * <code>text</code> is <code>null</code>, the empty * string <code>""</code> will be displayed * @param rows the number of rows; if * <code>rows</code> is less than <code>0</code>, * <code>rows</code> is set to <code>0</code> * @param columns the number of columns; if * <code>columns</code> is less than <code>0</code>, * <code>columns</code> is set to <code>0</code> * @param scrollbars a constant that determines what * scrollbars are created to view the text area * @exception HeadlessException if * <code>GraphicsEnvironment.isHeadless</code> returns true * @see java.awt.GraphicsEnvironment#isHeadless() * Construct a name for this component. Called by <code>getName</code> * when the name is <code>null</code>. * Creates the <code>TextArea</code>'s peer. The peer allows us to modify * the appearance of the <code>TextArea</code> without changing any of its * Inserts the specified text at the specified position * <p>Note that passing <code>null</code> or inconsistent * parameters is invalid and will result in unspecified * @param str the non-<code>null</code> text to insert * @param pos the position at which to insert * @see java.awt.TextComponent#setText * @see java.awt.TextArea#replaceRange * @see java.awt.TextArea#append * @deprecated As of JDK version 1.1, * replaced by <code>insert(String, int)</code>. * Appends the given text to the text area's current text. * <p>Note that passing <code>null</code> or inconsistent * parameters is invalid and will result in unspecified * @param str the non-<code>null</code> text to append * @see java.awt.TextArea#insert * @deprecated As of JDK version 1.1, * replaced by <code>append(String)</code>. * Replaces text between the indicated start and end positions * with the specified replacement text. The text at the end * position will not be replaced. The text at the start * position will be replaced (unless the start position is the * same as the end position). * The text position is zero-based. The inserted substring may be * of a different length than the text it replaces. * <p>Note that passing <code>null</code> or inconsistent * parameters is invalid and will result in unspecified * @param str the non-<code>null</code> text to use as * @param start the start position * @param end the end position * @see java.awt.TextArea#insert * @deprecated As of JDK version 1.1, * replaced by <code>replaceRange(String, int, int)</code>. * Returns the number of rows in the text area. * @return the number of rows in the text area * Sets the number of rows for this text area. * @param rows the number of rows * @exception IllegalArgumentException if the value * supplied for <code>rows</code> * is less than <code>0</code> * Returns the number of columns in this text area. * @return the number of columns in the text area * Sets the number of columns for this text area. * @param columns the number of columns * @exception IllegalArgumentException if the value * supplied for <code>columns</code> * is less than <code>0</code> * Returns an enumerated value that indicates which scroll bars * The <code>TextArea</code> class defines four integer constants * that are used to specify which scroll bars are available. * <code>TextArea</code> has one constructor that gives the * application discretion over scroll bars. * @return an integer that indicates which scroll bars are used * @see java.awt.TextArea#SCROLLBARS_BOTH * @see java.awt.TextArea#SCROLLBARS_VERTICAL_ONLY * @see java.awt.TextArea#SCROLLBARS_HORIZONTAL_ONLY * @see java.awt.TextArea#SCROLLBARS_NONE * @see java.awt.TextArea#TextArea(java.lang.String, int, int, int) * Determines the preferred size of a text area with the specified * number of rows and columns. * @param rows the number of rows * @param columns the number of columns * @return the preferred dimensions required to display * the text area with the specified * number of rows and columns * @see java.awt.Component#getPreferredSize * @deprecated As of JDK version 1.1, * replaced by <code>getPreferredSize(int, int)</code>. * Determines the preferred size of this text area. * @return the preferred dimensions needed for this text area * @see java.awt.Component#getPreferredSize * @deprecated As of JDK version 1.1, * replaced by <code>getPreferredSize()</code>. * Determines the minimum size of a text area with the specified * number of rows and columns. * @param rows the number of rows * @param columns the number of columns * @return the minimum dimensions required to display * the text area with the specified * number of rows and columns * @see java.awt.Component#getMinimumSize * @deprecated As of JDK version 1.1, * replaced by <code>getMinimumSize(int, int)</code>. * Determines the minimum size of this text area. * @return the preferred dimensions needed for this text area * @see java.awt.Component#getPreferredSize * @deprecated As of JDK version 1.1, * replaced by <code>getMinimumSize()</code>. * Returns a string representing the state of this <code>TextArea</code>. * This method is intended to be used only for debugging purposes, and the * content and format of the returned string may vary between * implementations. The returned string may be empty but may not be * @return the parameter string of this text area * The textArea Serialized Data Version. * Read the ObjectInputStream. * @exception HeadlessException if * <code>GraphicsEnvironment.isHeadless()</code> returns * @see java.awt.GraphicsEnvironment#isHeadless // HeadlessException will be thrown by TextComponent's readObject // Make sure the state we just read in for columns, rows, // and scrollbarVisibility has legal values * Returns the <code>AccessibleContext</code> associated with * this <code>TextArea</code>. For text areas, the * <code>AccessibleContext</code> takes the form of an * <code>AccessibleAWTTextArea</code>. * A new <code>AccessibleAWTTextArea</code> instance is created if necessary. * @return an <code>AccessibleAWTTextArea</code> that serves as the * <code>AccessibleContext</code> of this <code>TextArea</code> * This class implements accessibility support for the * <code>TextArea</code> class. It provides an implementation of the * Java Accessibility API appropriate to text area user-interface elements. * JDK 1.3 serialVersionUID * Gets the state set of this object. * @return an instance of AccessibleStateSet describing the states * @see AccessibleStateSet