JDK-6418233 : JComboBox has improper margins on Windows XP
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 5.0,6
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: windows_xp
  • CPU: x86
  • Submitted: 2006-04-26
  • Updated: 2011-02-16
  • Resolved: 2006-07-11
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 6
6Resolved
Related Reports
Duplicate :  
Duplicate :  
Relates :  
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.

Comments
EVALUATION This bug has the same root cause as another one that must be fixed: 6439971 (it's a regression), so I'm bumping it back up to Mustang.
29-06-2006

EVALUATION The fix for 6382711 did fix a lot of combo box issues but not this one. A non-editable combobox will have the correct insets but an editable one still has the wrong margins. However, it is too late in the release cycle to get this in for mustang so I'm pushing it to dolphin.
13-06-2006

EVALUATION This should be fixed by the changes for bug 6382711
01-05-2006