|
Quick Lists
|
|
Bug ID:
|
4337049
|
|
Votes
|
1
|
|
Synopsis
|
Background color on JComboBox also changes color of drop down button
|
|
Category
|
java:classes_swing
|
|
Reported Against
|
1.3
|
|
Release Fixed
|
1.4(merlin-beta)
|
|
State
|
10-Fix Delivered,
bug
|
|
Priority:
|
4-Low
|
|
Related Bugs
|
|
|
Submit Date
|
10-MAY-2000
|
|
Description
|
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 xxxxx 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)
======================================================================
|
|
Work Around
|
N/A
|
|
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.
xxxxx@xxxxx 2000-05-15
|
|
Comments
|
Submitted On 08-DEC-2000
BrighamBell
/* workaround for 4337049 */
package com.emperative.tool.util.table;
import javax.swing.*;
import java.awt.*;
public class ComboBox4337049 extends JComboBox {
public void setBackground(Color bg) {
super.setBackground(bg);
// set the background of the arrow box to lightgray
// whenever the background of the background of the
// combobox is set.
try {
Class arrowClass = Class.forName("javax.swing.plaf.basic.BasicArrowButton");
Component c = findComponent(this, arrowClass);
if(c != null) c.setBackground(Color.lightGray);
}
catch(ClassNotFoundException ignore) {
}
}
/**
* Return the first component in the given container-component hierarchy
* that is assignable to the given class. Traverses the container-component
* hierarchy (starting from the supplied component) until a component
* with this class is found.
* @param comp the component (or Container) from which to start searching
* @param componentClass the class of component to find in the hierarchy
*/
public static Component findComponent(Component comp, Class componentClass) {
if(componentClass.isAssignableFrom(comp.getClass()))
return comp;
else if(comp instanceof Container) {
Container container = (Container)comp;
int ncomponents = container.getComponentCount();
Component component[] = container.getComponents();
for(int i = 0 ; i < ncomponents ; i++) {
Component inComp = findComponent(component[i], componentClass);
if(inComp != null) return inComp;
}
}
return null;
}
}
Submitted On 09-MAY-2001
vaidal
"Easy solution:
The foreground and background PropertyChangeHandler should
be moved from
BasicComboBoxUI to MetalComboBoxUI."
ummmm How do I move it?
PLEASE NOTE: JDK6 is formerly known as Project Mustang
|
|
|
 |