Glazed List 和 Nimbus 中的背景颜色
我对 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);
}
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);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于Nimbus,你必须覆盖nimbus UI默认更多此处
for Nimbus you have to override nimbus UI default more here
组合框由多个组件组成。您需要在组合框中设置实际编辑器组件的背景颜色:
ComboBoxes are made up of multiple components. You need to set the background color on the actual editor component in the combo box: