218 synchronized (getTreeLock()) { 219 TextComponentPeer peer = (TextComponentPeer)this.peer; 220 if (peer != null) { 221 text = peer.getText(); 222 selectionStart = peer.getSelectionStart(); 223 selectionEnd = peer.getSelectionEnd(); 224 } 225 super.removeNotify(); 226 } 227 } 228 229 /** 230 * Sets the text that is presented by this 231 * text component to be the specified text. 232 * @param t the new text; 233 * if this parameter is <code>null</code> then 234 * the text is set to the empty string "" 235 * @see java.awt.TextComponent#getText 236 */ 237 public synchronized void setText(String t) { 238 text = (t != null) ? t : ""; 239 TextComponentPeer peer = (TextComponentPeer)this.peer; 240 if (peer != null) { 241 peer.setText(text); 242 } 243 } 244 245 /** 246 * Returns the text that is presented by this text component. 247 * By default, this is an empty string. 248 * 249 * @return the value of this <code>TextComponent</code> 250 * @see java.awt.TextComponent#setText 251 */ 252 public synchronized String getText() { 253 TextComponentPeer peer = (TextComponentPeer)this.peer; 254 if (peer != null) { 255 text = peer.getText(); 256 } 257 return text; | 218 synchronized (getTreeLock()) { 219 TextComponentPeer peer = (TextComponentPeer)this.peer; 220 if (peer != null) { 221 text = peer.getText(); 222 selectionStart = peer.getSelectionStart(); 223 selectionEnd = peer.getSelectionEnd(); 224 } 225 super.removeNotify(); 226 } 227 } 228 229 /** 230 * Sets the text that is presented by this 231 * text component to be the specified text. 232 * @param t the new text; 233 * if this parameter is <code>null</code> then 234 * the text is set to the empty string "" 235 * @see java.awt.TextComponent#getText 236 */ 237 public synchronized void setText(String t) { 238 239 // Please note that we do not want to post an event 240 // if TextArea.setText() or TextField.setText() replaces an empty text 241 // by an empty text, that is, if component's text remains unchanged. 242 if ((text == null || text.isEmpty()) && (t == null || t.isEmpty())) { 243 return; 244 } 245 246 text = (t != null) ? t : ""; 247 TextComponentPeer peer = (TextComponentPeer)this.peer; 248 if (peer != null) { 249 peer.setText(text); 250 } 251 } 252 253 /** 254 * Returns the text that is presented by this text component. 255 * By default, this is an empty string. 256 * 257 * @return the value of this <code>TextComponent</code> 258 * @see java.awt.TextComponent#setText 259 */ 260 public synchronized String getText() { 261 TextComponentPeer peer = (TextComponentPeer)this.peer; 262 if (peer != null) { 263 text = peer.getText(); 264 } 265 return text; |