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

Background color on JComboBox also changes color of drop down button

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P4 P4
    • 1.4.0
    • 1.3.0
    • client-libs
    • beta
    • x86
    • windows_nt



      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)
      ======================================================================

            mdavidsosunw Mark Davidson (Inactive)
            rlewis Roger Lewis (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: