Shading Rows and Columns in a JTable Component
import java.awt.Color;
import java.awt.Component;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
public class Main {
public static void main(String[] argv) {
JTable table = new JTable() {
public Component prepareRenderer(TableCellRenderer renderer, int rowIndex, int vColIndex) {
Component c = super.prepareRenderer(renderer, rowIndex, vColIndex);
if (rowIndex % 2 == 0 && !isCellSelected(rowIndex, vColIndex)) {
c.setBackground(Color.yellow);
} else {
c.setBackground(getBackground());
}
return c;
}
};
}
}
Related examples in the same category