Search code examples
javaautocompletecomboboxnimbusglazedlists

Background color in Glazed List and Nimbus


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

}

Solution

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

    for Nimbus you have to override nimbus UI default more here