I want to change the background color of particular table header. In my appliaction I have to set header color Red on the current month.
My Code is here::
jTable1.getTableHeader().
setDefaultRenderer(
new DefaultTableHeaderCellRenderer());
@Override
public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
super.getTableCellRendererComponent(table, value,
isSelected, hasFocus, row, column);
JTableHeader tableHeader = table.getTableHeader();
if(column==1)
tableHeader.setBackground(Color.red);
return this;
}
这使得所有标题颜色都是红色的。
请给我一些建议。
提前致谢。
DefaultTableCellRenderer 臭名昭著的颜色记忆:-) 你必须
- 始终设置背景颜色:即适用于正常状态和突出显示状态
- do so before呼叫超级
就像是:
@Override
public Component getTableCellRendererComponent(JTable table,
Object value, boolean isSelected, boolean hasFocus, int row,
int column) {
if (myHighlightCondition) {
setBackground(Color.RED);
} else {
setBackground(null);
}
super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
row, column);
return this;
}
有关更多详细信息(以及为什么需要它),请参阅如何正确使用自定义渲染器来绘制 JTable 中的特定单元格?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)