釉面列表和雨云中的背景颜色

时间:2011-10-28 15:59:49

标签: java autocomplete combobox nimbus glazedlists

我对来自Glazed Lists的组合框使用自动完成功能。这非常有用。我也使用nibus L& F.但它忽略了JCombobox.setBackground(Color)。有没有办法强制使用nimbus将backgroundcolor强制为红色?

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 个答案:

答案 0 :(得分:3)

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

对于Nimbus,你必须覆盖nimbus UI默认更多here

答案 1 :(得分:1)

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

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