Background color in Glazed List and Nimbus
-
16-02-2021 - |
Pregunta
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);
}
Otros consejos
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);
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow