[英]change jtable row color
I use this code on jtable customize code in custom creation but my selected row not changed please help me for soft this problem我在 jtable 上使用此代码在自定义创建中自定义代码但我选择的行没有改变请帮我解决这个问题
jtablexml = new javax.swing.JTable(){
public Component prepareRenderer ( TableCellRenderer renderer, int row, int column ){
Component component = super.prepareRenderer(renderer,row,column);
Object value = getModel().getValueAt(row,column);
if(value.equals(null)){
component.setBackground(Color.RED);
component.setForeground(Color.BLACK); }
else{
component.setBackground(Color.WHITE);
component.setForeground(Color.BLACK); }
jtablexml.setSelectionBackground(Color.GREEN);
return component; }
}; };
but my selected row not changed
但我选择的行没有改变
Your logic overrides the default selection of the row.您的逻辑会覆盖该行的默认选择。
You need an additional check to make sure the row is not highlighted by default:您需要额外检查以确保默认情况下未突出显示该行:
Component component = super.prepareRenderer(renderer,row,column);
if (!isRowSelected(row))
{
// add custom highlighting here
}
return component;
SeeTable Row Rendering for other row rendering examples.有关其他行渲染示例,请参阅表格行渲染。
Also, don't try to change a property of the table in the renderer.另外,不要尝试在渲染器中更改表的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.