Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4966585

Win L&F: JComboBox problems with XP style

    XMLWordPrintable

    Details

    • Subcomponent:
    • Resolved In Build:
      b43
    • CPU:
      x86
    • OS:
      windows_xp

      Description



      Name: gm110360 Date: 12/10/2003


      FULL PRODUCT VERSION :
      java version "1.4.2_01"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_01-b06)
      Java HotSpot(TM) Client VM (build 1.4.2_01-b06, mixed mode)

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

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      Using XP desktop style

      A DESCRIPTION OF THE PROBLEM :
      Not enough width for text box in JComboBox with XP desktop style. With native code and XP style, there is white space to the left of the text in a drop-down combo box. With Java 1.4.2 (and 1.5) there is no space, and if using the XP standard font (Tahoma 11pt) the space may be so small that only an ellipsis (...) shows.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      The following code shows the problem. It shows two JComboBox components, the left one with the default font (which is incorrectly MS Sans Serif for me) and the right one with correct XP system font (Tahoma). Neither has space to the left of the text, and the Tahoma one only shows an ellipsis for the text.

      import java.awt.*;
      import java.awt.event.*;
      import javax.swing.*;

      public class bug4966585 extends JComboBox {

          bug4966585() {
      // Combo box with short entries
      addItem("ms");
      addItem("s");
      addItem("m");
      addItem("h");

      // Workaround
      // setPreferredSize(new Dimension(getPreferredSize().width + 1,
      // getPreferredSize().height));
          }

          void PrintInfo(int i) {
      // Print out font info and control sizes
      Font f = getFont();
      FontMetrics fm = getFontMetrics(f);
      System.out.println("ComboBox " + i +":");
      System.out.println("Font: " + f.toString());
      System.out.println("FontMetrics: " + fm.toString());
      System.out.println("Combo width: " + getSize().width);
      System.out.println("String width: " + fm.stringWidth((String)getItemAt(1)));
          }

          public static void main(String[] args) {
      try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
      } catch(Exception e) {
      System.out.println(e);
      }

      JFrame f = new JFrame("XPComboBox test");
      f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      Container c = f.getContentPane();
      c.setLayout(new FlowLayout());

      // Use default font (not XP standard) for 1st combo
      bug4966585 cb1 = new bug4966585();
      c.add(cb1);

      // Use standard XP font for 2nd combo
      bug4966585 cb2 = new bug4966585();
      cb2.setFont(new Font("Tahoma", Font.PLAIN, cb1.getFont().getSize()));
      c.add(cb2);

      f.pack();
      f.setVisible(true);

      // Print out font info and control sizes
      cb1.PrintInfo(1);
      cb2.PrintInfo(2);
          }
      }


      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The JComboBox with Tahoma font should not just show an ellipsis, and both combo boxes should have some whitespace to the left of the text (as in the native XP combo box).
      ACTUAL -
      The right hand combo box just shows an ellipsis.
      Neither combo box has white space to the left of the text.

      REPRODUCIBILITY :
      This bug can be reproduced always.
      (Incident Review ID: 230009)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              kereminsunw Konstantin Eremin (Inactive)
              Reporter:
              gmanwanisunw Girish Manwani (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: