I have a JTable where I want to highlight some lines using my own background color. I did this with the following class:
public class MyTable extends JTable {
private List<RefData> data = null;
public List<RefData> getData() {
return data;
}
public void setData(List<RefData> data) {
this.data = data;
}
@Override
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component comp = super.prepareRenderer(renderer, row, column);
if (this.data == null || row < 0 || row > this.data.size()-1){
return comp;
}
RefData rowData = this.data.get(row);
if (rowData.getStatus() < 3000){
comp.setBackground(Color.YELLOW);
} else {
comp.setBackground(Color.WHITE);
}
return comp;
}
}
It all works like a charm, and I get exactly what I want. Then, looking at the resulting graphical interface, I understand that the table looks too compressed. Everything looks bad. As always with JTable defaults;)
Well, this is easy to solve, I thought:
myTable.setIntercellSpacing(new java.awt.Dimension(10, 1));
Now the cells are well spaced , but the added cell fields are now in the background color of the table by default, which in my case is white. It looks indecent.
, , prepareRenderer. . ?
prepareRenderer ? ?