changeset 4401:3ac81907aa7d

6509273: Password in JPasswordField gets Printed in clear text Reviewed-by: alexp
author rupashka
date Mon, 18 Jul 2011 17:40:12 +0400
parents 9c642ae9a543
children c05b36e4749e
files src/share/classes/sun/swing/text/TextComponentPrintable.java
diffstat 1 files changed, 17 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/sun/swing/text/TextComponentPrintable.java	Fri Jul 15 19:25:06 2011 +0400
+++ b/src/share/classes/sun/swing/text/TextComponentPrintable.java	Mon Jul 18 17:40:12 2011 +0400
@@ -47,15 +47,7 @@
 import java.util.concurrent.FutureTask;
 import java.util.concurrent.atomic.AtomicReference;
 
-import javax.swing.BorderFactory;
-import javax.swing.CellRendererPane;
-import javax.swing.JTextField;
-import javax.swing.JTextArea;
-import javax.swing.JEditorPane;
-import javax.swing.JViewport;
-import javax.swing.JScrollPane;
-import javax.swing.JTextPane;
-import javax.swing.SwingUtilities;
+import javax.swing.*;
 import javax.swing.border.Border;
 import javax.swing.border.TitledBorder;
 import javax.swing.text.BadLocationException;
@@ -336,7 +328,22 @@
         assert SwingUtilities.isEventDispatchThread();
 
         JTextComponent ret = null;
-        if (textComponent instanceof JTextField) {
+        if (textComponent instanceof JPasswordField) {
+            ret =
+                new JPasswordField() {
+                    {
+                        setEchoChar(((JPasswordField) textComponent).getEchoChar());
+                        setHorizontalAlignment(
+                            ((JTextField) textComponent).getHorizontalAlignment());
+                    }
+                    @Override
+                    public FontMetrics getFontMetrics(Font font) {
+                        return (frc.get() == null)
+                            ? super.getFontMetrics(font)
+                            : FontDesignMetrics.getMetrics(font, frc.get());
+                    }
+                };
+        } else if (textComponent instanceof JTextField) {
             ret =
                 new JTextField() {
                     {