< prev index next >
jdk/src/java.desktop/share/classes/java/awt/TextArea.java
Print this page
@@ -325,13 +325,13 @@
@Deprecated
public synchronized void insertText(String str, int pos) {
TextAreaPeer peer = (TextAreaPeer)this.peer;
if (peer != null) {
peer.insert(str, pos);
- } else {
- text = text.substring(0, pos) + str + text.substring(pos);
}
+ text = (text != null) ? text.substring(0, pos) + str
+ + text.substring(pos) : str;
}
/**
* Appends the given text to the text area's current text.
* <p>Note that passing <code>null</code> or inconsistent
@@ -341,11 +341,11 @@
* @param str the non-<code>null</code> text to append
* @see java.awt.TextArea#insert
* @since 1.1
*/
public void append(String str) {
- appendText(str);
+ insertText(str, getText().length());
}
/**
* Appends the given text to the text area's current text.
*
@@ -353,15 +353,11 @@
* @deprecated As of JDK version 1.1,
* replaced by <code>append(String)</code>.
*/
@Deprecated
public synchronized void appendText(String str) {
- if (peer != null) {
insertText(str, getText().length());
- } else {
- text = text + str;
- }
}
/**
* Replaces text between the indicated start and end positions
* with the specified replacement text. The text at the end
@@ -401,13 +397,13 @@
@Deprecated
public synchronized void replaceText(String str, int start, int end) {
TextAreaPeer peer = (TextAreaPeer)this.peer;
if (peer != null) {
peer.replaceRange(str, start, end);
- } else {
- text = text.substring(0, start) + str + text.substring(end);
}
+ text = (text != null) ? text.substring(0, start) + str
+ + text.substring(end) : str;
}
/**
* Returns the number of rows in the text area.
* @return the number of rows in the text area
< prev index next >