0

I use a autocomplete feature for comboboxes from Glazed Lists. It's pretty usefull. I also use nibus L&F. But it ignores JCombobox.setBackground(Color). Is there any way to force backgroundcolor to be for example red using nimbus?

Examplecode:

SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
    final JFrame frame = new JFrame();
    JComboBox cbox = new JComboBox();
    String[] strs = {"Nowarro", "Klamat", "Den", "NKR"};
    try {
        UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
    } catch (Throwable e1) {
        e1.printStackTrace();
    }
    AutoCompleteSupport.install(cbox, GlazedLists.eventList(Arrays.asList(strs)));
    cbox.setBackground(Color.RED); // NO EFFECT!!!
    frame.getContentPane().add(cbox);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);

}
oliholz
  • 7,447
  • 2
  • 43
  • 82
AvrDragon
  • 7,139
  • 4
  • 27
  • 42

2 Answers2

3
Color color = UIManager.getColor
      ("ComboBox:\"ComboBox.renderer\"[Selected].background");

for Nimbus you have to override nimbus UI default more here

mKorbel
  • 109,525
  • 20
  • 134
  • 319
1

ComboBoxes are made up of multiple components. You need to set the background color on the actual editor component in the combo box:

cbox.getEditor().getEditorComponent().setBackground(Color.red);
Reverend Gonzo
  • 39,701
  • 6
  • 59
  • 77
  • Take a look at: http://stackoverflow.com/questions/613603/java-nimbus-laf-with-transparent-text-fields It looks like Nimbus has transparent text fields that you'll need to set to be opaque. – Reverend Gonzo Oct 28 '11 at 16:13