在没有渲染器的情况下更改JComboBox颜色

时间:2011-07-27 12:20:30

标签: java swing combobox nimbus uimanager

我可以使用以下方法更改ComboBox背景颜色:

UIManager.put("ComboBox.background", Color.RED);

它有效。

但要更改 [selected] .background ,查看Nimbus Defaults该属性称为 ComboBox:“ComboBox.listRenderer”[Selected] .background ,所以我尝试了:

UIManager.put("ComboBox:\"ComboBox.listRenderer\"[Selected].background", Color.RED);

但它不起作用。

我想用渲染器(我已经尝试过,并且在很长的代码中提出了很多问题,我甚至没有自己写过,如果我这样做,将组合框渲染到JFileChoosers中是一个额外的问题)。那么,有没有解决方案可以使用UIMAnager.put()?

来解决这个问题

1 个答案:

答案 0 :(得分:1)

设置不同的Color,而不使用Nimbus defaluts

1 /单独的JComboBox

((JTextField) myJComboBox.getEditor().getEditorComponent())
#setBackground(Color.xxxx);

2 / JFileChooser

  • JComponents(化合物JFileChooser)中提取所有JComponentshere,与JList和{{1}相同}

  • JScrooPane提取所有JComponents的最安全方式,如您之前发布的关于该here

  • 的帖子所示

3 /使用JFileChooser查找defalut

  • NimbusDefalut以及我的添加No.1

  • 中的建议
  • JTextField来自JComboBox's DropDown List的defaluts,HighLighter可供选择JList

编辑:

JTable
相关问题