使用jtable创建了一个表格,并把表格中某些行设置了底色(用以区分特殊的数据),现在的问题是,当选择一个有底色的行时,该行底色变成了灰色,原来的底色看不见了,请问有什么解决方案。号小分不多,请见谅。
解决方案 »
- 我的oracle cursor 指针不下移
- 程序编译成功,但是在操作时候显示【java.lang.NullPointerException】,我又找不出哪里有问题,谁看看
- 如何循环添加按钮--基于酒店管理系统
- 像tomcat6w.exe和eclipse.exe这种运行JAVA程序的exe文件是如何建立的
- 大家幫幫忙,myeclipse里面怎么進行java的GUI設計!
- 请问JTextField 和TextField有什么区别?
- DATE()使用的问题
- 现在与未来,请指路!谢谢!
- 关于“char[] ”型数组的显示问题
- socket连接时,服务器怎么知道另外客户机断开连接了
- 谁有jdk1.6的下载地址啊???
- SWT/JFACE界面如何通过按钮改变?
public class TableViewRenderer extends DefaultTableCellRenderer { private Color unselectedForeground;
private Color unselectedBackground; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
boolean hasFocus, int row, int column) { if (isSelected) {
component.setForeground( table.getSelectionForeground());
component.setBackground(table.getSelectionBackground());
} else {
component.setForeground((unselectedForeground != null) ? unselectedForeground
: table.getForeground());
component.setBackground((unselectedBackground != null) ? unselectedBackground
: table.getBackground());
}
setFont(table.getFont());
setValue(value);
return this;
}
}
}
component.setForeground( Color );
component.setBackground(Color); //这里的颜色设定你选中时想要的颜色
} else {
component.setForeground();
component.setBackground(); // 这里的颜色设定你不选中时想要的颜色
}
setBackground()肯定是改变背景色,肯定是要改CellRenderer,具体的代码就要根据你的实际功能来写了