JDK-4224190 : JTextField getColumnWidth is inaccurate
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.1.7,1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: generic,windows_95
  • CPU: generic,x86
  • Submitted: 1999-03-26
  • Updated: 2003-01-31
  • Resolved: 2003-01-31
Related Reports
Relates :  
Description
Name: vi73552			Date: 03/25/99

The JTextField getColumnWidth method should return
a width that is the average of common characters for
the font, instead of just returning the width of the
character 'm'.  As currently implemented, getColumnWidth
causes JTextFields to be wider than requested.  This
complicates AWT to swing conversions since column
widths need to be adjusted.
(Review ID: 55401) 
======================================================================

Name: mc57594			Date: 01/05/2000
JRE      build 1.3beta-0
Hotspot  build 1.3beta-0

When the number of columns is specified for a JTextField, the preferred width
calculated for the field is too small. The documentation states the column
width is that of the character 'm' of the font in use.

See attached program. Number of columns is set to 4, but enter 4 'm's in the
field and only 3.5 are visible. This occurs with the Metal/Java look and feel.

----------------------------------------------------------------------------
import javax.swing.*;

public class Test2
{
    public static void main(String[] args)
    {
        JFrame f = new JFrame();
        JPanel p = new JPanel();
        JTextField t = new JTextField(4);
        p.add(t);
        f.getContentPane().add(p);
        f.pack();
        f.setVisible(true);
    }
}
(Review ID: 99006)
======================================================================

The part about :
"See attached program. Number of columns is set to 4, but enter 4 'm's in the
field and only 3.5 are visible. This occurs with the Metal/Java look and feel."
is covered by 4426701

###@###.### 2002-05-23

Comments
EVALUATION The value used should be the maximum character advance for the font. this is actually a bug and not an rfe. timothy.prinzing@eng 2000-03-22 Name: ik75403 Date: 01/31/2003 Many applications depend upon the current behaviour. It is to dangerous to change it. Closing as will not fix ======================================================================
11-06-2004

WORK AROUND Name: vi73552 Date: 03/25/99 Override getColumnWidth to compute the width more accurately. ======================================================================
11-06-2004