1 30 31 package com.jgoodies.looks.common; 32 33 import java.awt.Container ; 34 import java.awt.Graphics ; 35 import java.awt.Graphics2D ; 36 import java.awt.RenderingHints ; 37 38 import javax.swing.JPasswordField ; 39 import javax.swing.text.Element ; 40 import javax.swing.text.PasswordView ; 41 42 49 public final class ExtPasswordView extends PasswordView { 50 51 public ExtPasswordView(Element element) { 52 super(element); 53 } 54 55 59 protected int drawEchoCharacter(Graphics g, int x, int y, char c) { 60 Container container = getContainer(); 61 if (!(container instanceof JPasswordField )) 62 return super.drawEchoCharacter(g, x, y, c); 63 64 JPasswordField field = (JPasswordField ) container; 65 int charWidth = getFontMetrics().charWidth(field.getEchoChar()); 66 int advance = 2; 67 int diameter = charWidth - advance; 68 69 Graphics2D g2 = (Graphics2D ) g; 71 Object oldHints = g2.getRenderingHint(RenderingHints.KEY_ANTIALIASING); 72 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 73 RenderingHints.VALUE_ANTIALIAS_ON); 74 75 g.fillOval(x, y - diameter, diameter, diameter); 77 g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldHints); 78 80 83 return x + diameter + advance; 84 } 85 86 87 } | Popular Tags |