Java 釉面列表和光晕中的背景色

Java 釉面列表和光晕中的背景色,java,autocomplete,combobox,nimbus,glazedlists,Java,Autocomplete,Combobox,Nimbus,Glazedlists,我对列表中的组合框使用自动完成功能。这很有用。我也使用尼伯斯L&F,但它忽略了JCombobox.setBackgroundColor。是否有任何方法可以使用nimbus强制背景颜色为红色 示例代码: SwingUtilities.invokeLater(new Runnable() { @Override public void run() { final JFrame frame = new JFrame(); JComboBox cbox = new JComboBox()

我对列表中的组合框使用自动完成功能。这很有用。我也使用尼伯斯L&F,但它忽略了JCombobox.setBackgroundColor。是否有任何方法可以使用nimbus强制背景颜色为红色

示例代码:

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

}

组合框由多个组件组成。您需要在组合框中设置实际编辑器组件的背景色:

cbox.getEditor().getEditorComponent().setBackground(Color.red);

组合框由多个组件组成。您需要在组合框中设置实际编辑器组件的背景色:

cbox.getEditor().getEditorComponent().setBackground(Color.red);
因为您必须更多地覆盖nimbus UI默认值

因为您必须更多地覆盖nimbus UI默认值

看一看:nimbus的透明文本字段需要设置为不透明。看一看:nimbus的透明文本字段需要设置为不透明。