Background color in Glazed List and Nimbus

863 Views Asked by At

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

}
2

There are 2 best solutions below

0
On BEST ANSWER
Color color = UIManager.getColor
      ("ComboBox:\"ComboBox.renderer\"[Selected].background");

for Nimbus you have to override nimbus UI default more here

1
On

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