JDK-6355380 : JPasswordField is too tall in Windows XP LAF
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2005-11-25
  • Updated: 2010-04-02
  • Resolved: 2006-03-10
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 7
7Resolved
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.5.0_05"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_05-b05)
Java HotSpot(TM) Client VM (build 1.5.0_05-b05, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows XP [Version 5.1.2600]

A DESCRIPTION OF THE PROBLEM :
For some reasone the default height of a JPasswordField is larger than than for a JTextField, at least with the Windows LaF. This makes simple forms containing  simple username + password entry fields to look bad.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Using a layout that will not distort the preferred size, show both a JTextField and a JPasswordField side by side.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
JPasswordField should have the same default height as a JTextField.
ACTUAL -
JPasswordField is a few pixels taller than a JTextField.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class TallPassword {
	public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
		// Run on Winows
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
		JFrame f = new JFrame("JPasswordField Height Problem");
		JPanel p = new JPanel();
		p.add(new JLabel("User name:"));
		p.add(new JTextField(16));
		p.add(new JLabel("Password:"));
		p.add(new JPasswordField(16));
		f.setContentPane(p);
		f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		f.pack();
		f.setVisible(true);
	}
}

---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
Forcibly set the preferred size of the JPasswordField to match that of a JTextField using setPreferredSize.

Comments
EVALUATION This was fixed by switching the font from FixedControlFont to ControlFont in 4985353.
10-03-2006

EVALUATION The Windows password field appears to have a 2px margin that the basic version doesn't have. This happens in both XP and classic mode, though it appears to be less in classic (1px instead of 2px) but the extra padding is the same. Very odd. Recent versions of Mustang don't appear to have this bug anymore, but I'm not sure why. Must try more builds.
07-03-2006