7124528: [macosx] Selection is not cleared properly in text component.
authorserb
Thu, 05 Apr 2012 19:43:56 +0400
changeset 12399 6221283c619f
parent 12398 8e4c529b8184
child 12400 80e69bcb0b8e
7124528: [macosx] Selection is not cleared properly in text component. Reviewed-by: anthony, art
jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java
--- a/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java	Thu Apr 05 19:22:54 2012 +0400
+++ b/jdk/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java	Thu Apr 05 19:43:56 2012 +0400
@@ -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