src/macosx/classes/sun/lwawt/LWTextFieldPeer.java

Print this page

        

@@ -32,11 +32,11 @@
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusEvent;
 import java.awt.peer.TextFieldPeer;
 
-import javax.swing.JPasswordField;
+import javax.swing.*;
 import javax.swing.text.JTextComponent;
 
 final class LWTextFieldPeer
         extends LWTextComponentPeer<TextField, JPasswordField>
         implements TextFieldPeer, ActionListener {

@@ -48,11 +48,11 @@
         super(target, platformComponent);
     }
 
     @Override
     protected JPasswordField createDelegate() {
-        return new JTextAreaDelegate();
+        return new JPasswordFieldDelegate();
     }
 
     @Override
     public void initialize() {
         super.initialize();

@@ -69,13 +69,22 @@
 
     @Override
     public void setEchoChar(final char echoChar) {
         synchronized (getDelegateLock()) {
             getDelegate().setEchoChar(echoChar);
-            getDelegate().putClientProperty("JPasswordField.cutCopyAllowed",
-                                            getDelegate().echoCharIsSet()
-                                            ? Boolean.FALSE : Boolean.TRUE);
+            final boolean cutCopyAllowed;
+            final String focusInputMapKey;
+            if (echoChar != 0) {
+                cutCopyAllowed = false;
+                focusInputMapKey = "PasswordField.focusInputMap";
+            } else {
+                cutCopyAllowed = true;
+                focusInputMapKey = "TextField.focusInputMap";
+            }
+            getDelegate().putClientProperty("JPasswordField.cutCopyAllowed", cutCopyAllowed);
+            InputMap inputMap = (InputMap) UIManager.get(focusInputMapKey);
+            SwingUtilities.replaceUIInputMap(getDelegate(), JComponent.WHEN_FOCUSED, inputMap);
         }
     }
 
     @Override
     public Dimension getPreferredSize(final int columns) {

@@ -111,15 +120,15 @@
             setCaretPosition(0);
         }
         super.handleJavaFocusEvent(e);
     }
 
-    private final class JTextAreaDelegate extends JPasswordField {
+    private final class JPasswordFieldDelegate extends JPasswordField {
 
         // Empty non private constructor was added because access to this
         // class shouldn't be emulated by a synthetic accessor method.
-        JTextAreaDelegate() {
+        JPasswordFieldDelegate() {
             super();
         }
 
         @Override
         public boolean hasFocus() {