java – 不可编辑的JComboBox中下拉控件和边框的颜色
不可编辑的JComboBox中所选项目的背景颜色是一种蓝色:
我知道您可以将其更改为其他颜色,例如白色,例如使用following code: jComboBox1.setRenderer(new DefaultListCellRenderer() { @Override public void paint(Graphics g) { setBackground(Color.WHITE); setForeground(Color.BLACK); super.paint(g); } }); 这给你这样的东西: 但是,如果双击该组合框,其中一些变为灰色(带有三角形和边框的部分): 当你双击它时,有没有办法阻止这些部件变灰? 请注意,如果首先调用super.paint(),整个事物会变暗(包括“Select …”后面的部分),这样做无济于事. 解决方法
几件事:
>组合框的外观(显示区域,箭头,下拉)取决于LAF.你的屏幕截图建议使用WinXP.如果你必须支持任何其他LAF,一定要测试它,因为对一个LAF起作用的可能不适用于另一个.我发现对于JComboBoxes来说尤其如此. public static class CustomRenderer extends DefaultListCellRenderer { @Override public Component getListCellRendererComponent(JList list,Object value,int index,boolean isSelected,boolean cellHasFocus) { super.getListCellRendererComponent(list,value,index,isSelected,cellHasFocus); setBackground(Color.WHITE); setForeground(Color.BLACK); return this; } } JComboBox combo = new JComboBox(new Object[]{"Dog","Cat","Bird"}); combo.setBackground(Color.WHITE); combo.setForeground(Color.BLACK); combo.setFocusable(false); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |