2011-10-28 2 views
0

Glazed Listsのコンボボックスにオートコンプリート機能を使用します。それはかなり便利です。また、ニブルL & Fを使用します。ただし、JCombobox.setBackground(Color)は無視されます。背景色を、たとえば赤色を使用して赤色にする方法はありますか?Glazed Listと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); 

} 

答えて

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

よりhere

1

コンボボックスは、複数のコンポーネントで構成されています。あなたは、コンボボックス内の実際のエディタコンポーネントの背景色を設定する必要があります:あなたは光背UIのデフォルトをオーバーライドする必要がNimbusため

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

あなたが正しいですが、それは動作しません。 – AvrDragon

+0

を見てください:http://stackoverflow.com/questions/613603/java-nimbus-laf-with-transparent-text-fields Nimbusには透明なテキストフィールドがあり、これを不透明に設定する必要があります。 –