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