ComboPopup
I am trying to change the color of the combo popup box to white, I have tried two method, both overiding the comboUI createPopup() method:
public BasicComboPopup createPopup() {
BasicComboPopup p = new BasicComboPopup(comboBox);
p.setBackground(Color.WHITE);
return p;
}
public BasicComboPopup createPopup() {
BasicComboPopup p = new BasicComboPopup(comboBox);
Component c = p.getComponent();
c.setBackground(Color.WHITE);
return p;
}
neither are working,
Cheers,
Adam
[560 byte] By [
Naz027a] at [2007-10-2 19:36:20]

works OK via the renderer
class MyRenderer extends DefaultListCellRenderer
{
public Component getListCellRendererComponent(JList list,Object value,
int index,boolean isSelected,boolean cellHasFocus)
{
JLabel lbl = (JLabel)super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
lbl.setBackground(Color.YELLOW);
return lbl;
}
}
import javax.swing.*;
import java.awt.*;
class Testing extends JFrame
{
JComboBox cbo = new JComboBox(new String[]{"London","Madrid","New York","Rome","Sydney","Washington"});
public Testing()
{
setSize(150,75);
setLocation(400,300);
setDefaultCloseOperation(EXIT_ON_CLOSE);
JPanel jp = new JPanel();
jp.add(cbo);
getContentPane().add(jp);
cbo.setRenderer(new MyRenderer());//<-
}
class MyRenderer extends DefaultListCellRenderer
{
public Component getListCellRendererComponent(JList list,Object value,
int index,boolean isSelected,boolean cellHasFocus)
{
JLabel lbl = (JLabel)super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus);
lbl.setBackground(Color.YELLOW);
return lbl;
}
}
public static void main(String args[]){new Testing().setVisible(true);}
}