如何设置JComboBox选中项的背景色,请高手赐教,谢谢
解决方案 »
- 空前绝后的Java Swing实现的QQ聊天程序,支持文字图片文件表情发送
- 刚学线程,遇到了简单的问题,急急
- 怎么比较两个Date型的年月日
- 电子鼓程序,"Java Examples in Nutshell”中的例子,按键盘发声
- 菜鸟问题,但是还是要问
- 中文 win2000 控制面板->区域设置中一切正常,为何 java 得到的属性 file.encoding 不对?诸位碰到过这种情况吗?
- 关于数据库的连接
- thinking in java and core java的重载问题认我好纳闷
- RMI实现的烦恼?
- java实现runnabale的线程的static问题
- 提示框背景颜色问题
- 构造方法的问题
public MyCellRenderer() {
setOpaque(true);
} public Component getListCellRendererComponent(JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) { setText(value.toString()); Color background;
Color foreground; // check if this cell represents the current DnD drop location
JList.DropLocation dropLocation = list.getDropLocation();
if (dropLocation != null
&& !dropLocation.isInsert()
&& dropLocation.getIndex() == index) { background = Color.BLUE;
foreground = Color.WHITE; // check if this cell is selected
} else if (isSelected) {
background = Color.RED;
foreground = Color.WHITE; // unselected, and not the DnD drop location
} else {
background = Color.WHITE;
foreground = Color.BLACK;
}; setBackground(background);
setForeground(foreground); return this;
}
}