7124528: [macosx] Selection is not cleared properly in text component

Reviewed-by: swingler
diff --git a/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java b/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java
index fb94d0b..af923ef 100644
--- a/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java
@@ -31,6 +31,7 @@
 import java.awt.TextField;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.FocusEvent;
 import java.awt.peer.TextFieldPeer;
 
 import javax.swing.JPasswordField;
@@ -97,6 +98,21 @@
                                   getText(), e.getWhen(), e.getModifiers()));
     }
 
+    /**
+     * Restoring native behavior. We should sets the selection range to zero,
+     * when component lost its focus.
+     *
+     * @param e the focus event
+     */
+    @Override
+    protected void handleJavaFocusEvent(final FocusEvent e) {
+        if (e.getID() == FocusEvent.FOCUS_LOST) {
+            // In order to de-select the selection
+            setCaretPosition(0);
+        }
+        super.handleJavaFocusEvent(e);
+    }
+
     private final class JTextAreaDelegate extends JPasswordField {
 
         // Empty non private constructor was added because access to this