怎样让JList中的某些项显示不同的颜色? jList.setBackground(Color.RED)是设置背景色jList.setForeground(Color.RED)是设置前景色 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 嗯没有错要用到ListCellRenderer对它进行设置! 楼上说的没错class jListCellRenderer extends JLabel implements ListCellRenderer{ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { Font font = (Font)value; setText(font.getFamily()); setFont(font); setOpaque(true); setBackground(isSelected? list.getSelectionBackground(): list.getBackground()); setForeground(isSelected? list.getSelectionForeground(): list.getForeground()); return this; }}jList.setCellRenderer(new FontCellRenderer());不知道行不行? java小程序中的奇怪问题 问一个关于数据展示的问题,着急 JNI问题 解析票据号的问题? 急救!这个程序运行出错啦,唉………,各位帮看看吧 tomcat server.xml里面有一个shutdown 8005 如何快速的将字符串"2x+5y=11"中的2,5,11取出来并转换成整形? 我做了个有关inetaddress的不东西,怎么跑起来起书上面的不一样的啊? 在线等:用那个函数获取客户端发来的UDP报文的IP地址和端口号? 求用鼠标绘图代码 如何用java实现对用户硬盘的监视 DATE()使用的问题
{
public Component getListCellRendererComponent(JList list,
Object value, int index, boolean isSelected,
boolean cellHasFocus)
{
Font font = (Font)value;
setText(font.getFamily());
setFont(font);
setOpaque(true);
setBackground(isSelected? list.getSelectionBackground(): list.getBackground());
setForeground(isSelected? list.getSelectionForeground(): list.getForeground());
return this;
}
}jList.setCellRenderer(new FontCellRenderer());不知道行不行?