JDK-4337049 : Background color on JComboBox also changes color of drop down button
  • Type: Bug
  • Component: client-libs
  • Sub-Component: javax.swing
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: windows_nt
  • CPU: x86
  • Submitted: 2000-05-10
  • Updated: 2000-09-15
  • Resolved: 2000-09-15
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.
Other
1.4.0 betaFixed
Description

Name: rlT66838			Date: 05/10/2000


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-C)
Java HotSpot(TM) Client VM (build 1.3.0-C, mixed mode)

Setting the background color of a JComboBox also changes the color of the drop
down button in JDK 1.3. This makes the JComboBox look really ugly. This problem
did not exist in JDK 1.2.2.

For some reason, using the "Windows" look and feel with background of the
JComboBox set to Color.white works fine (i.e, the drop down button is grey as
usual), but any other color will change the color of the button.
 

Example code (tested with 1.3 and 1.2.2):

/* Test background color on JComboBox */

import javax.swing.*;
import java.util.*;
import java.awt.*;
    
    public class Test extends JFrame
    {
        public Test()
        {
            initLookAndFeel();
            
            Vector data = new Vector();
            data.add("Row 1");
            data.add("Row 2");
        
            JComboBox comboWhite = new JComboBox(data);
            comboWhite.setBackground(Color.white);
            JComboBox comboOtherColor = new JComboBox(data);
            comboOtherColor.setBackground(Color.blue);
            
            JPanel panel = new JPanel();
            panel.add(comboWhite);
            panel.add(comboOtherColor);
            
            getContentPane().add(panel);
            
        }

      private static final String LOOKANDFEEL = "Windows";
 //   private static final String LOOKANDFEEL = "Metal";


    private void initLookAndFeel()
    {
	    String lookAndFeel = null;

	    if (LOOKANDFEEL != null) {
    	    if (LOOKANDFEEL.equals("Metal")) {
	            lookAndFeel = UIManager.getCrossPlatformLookAndFeelClassName();
	        }
            else if (LOOKANDFEEL.equals("Windows")) {
    	        lookAndFeel= "com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
    	    }
        }
	     
        try {
	        UIManager.setLookAndFeel(lookAndFeel);
	    } catch (Exception e) {
	        System.err.println("Error LookAndFeel!");
	        System.err.println("Using the default look and feel.");
	        e.printStackTrace();
	    }
	}
        
        
    public static void main(String[] args)
    {
        
        Test test = new Test();
        test.setSize(new java.awt.Dimension(200,200));
        test.show();
      
    }
}
(Review ID: 104675) 
======================================================================

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin FIXED IN: merlin-beta INTEGRATED IN: merlin-beta
14-06-2004

EVALUATION This regression was introduced because of the fix for 4264926. That bug was reporting the oposite of this bug in that for the Metal LAF, changing the fg and bg colors should change the colors of all the components. This should have been restricted to metal only. Easy solution: The foreground and background PropertyChangeHandler should be moved from BasicComboBoxUI to MetalComboBoxUI. mark.davidson@Eng 2000-05-15
15-05-2000