< prev index next >

src/java.desktop/share/classes/java/awt/TextComponent.java

Print this page

        

@@ -227,21 +227,24 @@
      *                  if this parameter is <code>null</code> then
      *                  the text is set to the empty string ""
      * @see         java.awt.TextComponent#getText
      */
     public synchronized void setText(String t) {
+        TextComponentPeer peer = (TextComponentPeer)this.peer;
+        if (peer != null) {
+            text = peer.getText();
         boolean skipTextEvent = (text == null || text.isEmpty())
                 && (t == null || t.isEmpty());
         text = (t != null) ? t : "";
-        TextComponentPeer peer = (TextComponentPeer)this.peer;
         // Please note that we do not want to post an event
         // if TextArea.setText() or TextField.setText() replaces an empty text
         // by an empty text, that is, if component's text remains unchanged.
-        if (peer != null && !skipTextEvent) {
+            if (!skipTextEvent) {
             peer.setText(text);
         }
     }
+    }
 
     /**
      * Returns the text that is presented by this text component.
      * By default, this is an empty string.
      *
< prev index next >