JDK-4673893 : REGRESSION: 2-column size JTextField can not contain 2 characters
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.4.1
  • Priority: P3
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2002-04-24
  • Updated: 2002-05-21
  • Resolved: 2002-05-21
Related Reports
Duplicate :  
Description
###@###.### 2002-04-24

J2SE Version (please include all output from java -version flag):
  java version "1.4.1-beta"
  Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1-beta-b08)
  Java HotSpot(TM) Client VM (build 1.4.1-beta-b08, mixed mode)

Does this problem occur on J2SE 1.3 or 1.4?  Yes / No (pick one)
 No, works fine with 1.3 and 1.4FCS.

Operating System Configuration Information (be specific):
 Windows NT Version 4 (SP 6)

Bug Description:
 A JTextField created with a 2-column size is not able to contain 2 
 characters (2 columns).

Test Program:
/**
 * EntryFieldHopper.java
 */
import java.lang.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

/**
 * Class:   EntryFieldHopper
 */
public class EntryFieldHopper extends javax.swing.JFrame
   {
    /**
     * Constructor: EntryFieldHopper
     * @return instance of EntryFieldHopper
     */
    public EntryFieldHopper()
       {
        super();
        /* javax.swing.JFrame - Bean Properties */
        setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
        setName("JFrame");
        setTitle("Title");
        /* javax.swing.JFrame - sets Bounds */
        setBounds(50,100,400,400);
        /* javax.swing.JFrame - Adds Child */
        JDesktopPane desktopPane = new javax.swing.JDesktopPane();
        getContentPane().add(desktopPane,java.awt.BorderLayout.CENTER);

        JTextField textField = new JTextField(2);
        /* JTextField - Bean Properties */
        textField.setName("JTextField");
        textField.setLocation(35,50);
        textField.setSize(textField.getPreferredSize());
        textField.setText("99");

        JPanel panel =  new JPanel();
        /* JPanel - Bean Properties */
        panel.setName("JPanel");
        /* JPanel - set Layout */
        panel.setLayout(null);
        panel.add(textField);

        getContentPane().add(panel,java.awt.BorderLayout.CENTER);
        show();
       } /* End of Constructor: EntryFieldHopper */

    /**
     * Method: generalHandleException <br>
     * @param java.lang.Throwable exception
     * @return void
     */
    protected void generalHandleException(java.lang.Throwable exc)
       {
        exc.printStackTrace(System.err);
       } /* End of Method: generalHandleException */

    /**
     * Method: main <br>
     * Note: Called only if we're an application. <br>
     * @param java.lang.String[] args the command line arguments
     * @return void
     */
    public static void main(java.lang.String[] args)
       {
        try
           {
            /* Set native look and feel */
            //
javax.swing.UIManager.setLookAndFeel(javax.swing.UIManager.getSystemLookAndFeelClassName());


UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

            /* Creates new MainObject */
            EntryFieldHopper self = new EntryFieldHopper();
           } /* End try */
        catch (java.lang.Throwable exc)
           {
            exc.printStackTrace(System.err);
           } /* End catch */
       } /* End of Method: main */

   } /* End of Class: EntryFieldHopper */


Comments
EVALUATION Name: apR10133 Date: 05/18/2002 The problem is the default font used by JTexfField on Windows LAF is changed to use the Windows system font instead of font defined by Swing previously. The JTextField's preferred width is the number of columns multiplied by the column width (the width of 'm' for the current font). This width is distributed between the border and input area. As the font is changed and actually decreased while the border insets is unchanged the input area becomes too small to fit text "99". These changes were made at WindowsLookAndFeel.java Before changes Font: FontUIResource[family=dialog,name=Dialog,style=plain,size=12] Width of 'm': 11 JTextField's preferred size: width=22, height=22 Border's insets: left=3, right=3 Input area width: 16 Width of "99": 14 FIT. After Font: FontUIResource[family=sansserif,name=MS Sans Serif,style=plain,size=11] Width of 'm': 8 JTextField's preferred size: width=16, height=21 Border's insets: left=3, right=3 Input area width: 10 Width of "99": 12 DOESN'T FIT. ###@###.### ====================================================================== Name: apR10133 Date: 05/21/2002 The text field ignores insets when it calculate the preferred size. This bug is a part of problem described at bug #4426701, so I'll close it as duplicate. ###@###.### ======================================================================
24-08-2004

WORK AROUND Name: apR10133 Date: 05/18/2002 You could use one of the following: 1. Set the JTextField's font explicitly: textField.setFont(new Font("Dialog", Font.PLAIN, 12)); 2. Disable using of system fonts before the WinLAF is set: UIManager.put("Application.useSystemFontSettings", Boolean.FALSE); 3. Take the border's width into account when you set the textfield size. ###@###.### ======================================================================
24-08-2004