changeset 5239:004d53e61c3b

7124528: [macosx] Selection is not cleared properly in text component. Reviewed-by: anthony, art
author serb
date Thu, 05 Apr 2012 19:43:56 +0400
parents c87bdacb109e
children dc0d4cf71dfb
files src/macosx/classes/sun/lwawt/LWTextFieldPeer.java
diffstat 1 files changed, 16 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/macosx/classes/sun/lwawt/LWTextFieldPeer.java	Thu Apr 05 19:22:54 2012 +0400
+++ b/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