1

我对 Glazed Lists 中的组合框使用自动完成功能。它非常有用。我也使用 nibus L&F。但它忽略了 JCombobox.setBackground(Color)。有什么方法可以使用 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);

}
4

2 回答 2

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

对于Nimbus ,您必须在此处更多地覆盖 nimbus UI 默认值

于 2011-10-28T16:12:15.500 回答
1

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

cbox.getEditor().getEditorComponent().setBackground(Color.red);
于 2011-10-28T16:07:54.880 回答