7124528: [macosx] Selection is not cleared properly in text component.
Reviewed-by: anthony, art
--- 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