jdk/src/java.desktop/share/classes/java/awt/TextComponent.java
changeset 34803 02d97673db58
parent 32865 f9cb6e427f9e
child 35667 ed476aba94de
equal deleted inserted replaced
34802:f8f0def6f107 34803:02d97673db58
   227      *                  if this parameter is <code>null</code> then
   227      *                  if this parameter is <code>null</code> then
   228      *                  the text is set to the empty string ""
   228      *                  the text is set to the empty string ""
   229      * @see         java.awt.TextComponent#getText
   229      * @see         java.awt.TextComponent#getText
   230      */
   230      */
   231     public synchronized void setText(String t) {
   231     public synchronized void setText(String t) {
   232         boolean skipTextEvent = (text == null || text.isEmpty())
   232         if (t == null) {
   233                 && (t == null || t.isEmpty());
   233             t = "";
   234         text = (t != null) ? t : "";
   234         }
   235         TextComponentPeer peer = (TextComponentPeer)this.peer;
   235         TextComponentPeer peer = (TextComponentPeer)this.peer;
   236         // Please note that we do not want to post an event
   236         if (peer != null) {
   237         // if TextArea.setText() or TextField.setText() replaces an empty text
   237             text = peer.getText();
   238         // by an empty text, that is, if component's text remains unchanged.
   238             // Please note that we do not want to post an event
   239         if (peer != null && !skipTextEvent) {
   239             // if TextArea.setText() or TextField.setText() replaces text
   240             peer.setText(text);
   240             // by same text, that is, if component's text remains unchanged.
       
   241             if (!t.equals(text)) {
       
   242                 text = t;
       
   243                 peer.setText(text);
       
   244             }
       
   245         } else {
       
   246             text = t;
   241         }
   247         }
   242     }
   248     }
   243 
   249 
   244     /**
   250     /**
   245      * Returns the text that is presented by this text component.
   251      * Returns the text that is presented by this text component.