United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4337049 : Background color on JComboBox also changes color of drop down button

Details
Type:
Bug
Submit Date:
2000-05-10
Status:
Resolved
Updated Date:
2000-09-15
Project Name:
JDK
Resolved Date:
2000-09-15
Component:
client-libs
OS:
windows_nt
Sub-Component:
javax.swing
CPU:
x86
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.3.0
Fixed Versions:
1.4.0 (beta)

Related Reports

Sub Tasks

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


                                     
2004-06-14
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
                                     
2000-05-15



Hardware and Software, Engineered to Work Together