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

JComboBox has improper margins on Windows XP

    XMLWordPrintable

Details

    Description

      FULL PRODUCT VERSION :
      java version "1.5.0_06"

      ADDITIONAL OS VERSION INFORMATION :
      Windows XP [Version 5.1.2600]

      A DESCRIPTION OF THE PROBLEM :
      by default editable JComboBoxes have different margins around their text than
      JTextFields. On Windows XP JTextFields have about 5-6 pixels of left margin between the fields border and the contained text, however JComboBoxes have an left margin of 0 pixels.
      I took a dive into the code, and it looks to me as if this bug is caused by the fact that on Windows XP the LAF code uses a special border to create this margin, but the editor for comboboxes use a descendant of JTextField called BorderlessTextField which ignores the bordersetting. Inside the BasicComboBoxEditor source file you will find this line of code:

              public void setBorder(Border b) {}

      which overrides the normal setBorder method of JTextField. My tests have shown that the editor used for JComboBoxes do have an Insets margin, but it seems this is ignored, which lead me to speculate that the bug is caused by the setBorder method above.

      Whether or not my guesses are correct, the bug remains: JComboBoxes have different distanses between their border graphics and text when compared to JTextFields. This results in the two inner texts of the components not to be aligned even when the components themselves are aligned. Needles to say, this does not look correct.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      1. Create a simple dialog with a gridbaglayout.
      2. add a JComboBox directly above a JTextField and have them fill horizontally.
      3. make both components editable
      4. run your application and see that the texts contained in the
      components are not aligned.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Aligned texts
      ACTUAL -
      Texts that where not aligned.

      REPRODUCIBILITY :
      This bug can be reproduced always.

      Attachments

        Issue Links

          Activity

            People

              jmarinacsunw Joshua Marinacci (Inactive)
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: